From owner-p4-projects@FreeBSD.ORG Mon Nov 28 23:58:29 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8682116A422; Mon, 28 Nov 2005 23:58:28 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 470DB16A41F for ; Mon, 28 Nov 2005 23:58:28 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5166443D78 for ; Mon, 28 Nov 2005 23:58:23 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id jASNwNd4031223 for ; Mon, 28 Nov 2005 23:58:23 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id jASNwMdd031220 for perforce@freebsd.org; Mon, 28 Nov 2005 23:58:22 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Mon, 28 Nov 2005 23:58:22 GMT Message-Id: <200511282358.jASNwMdd031220@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 87394 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Nov 2005 23:58:29 -0000 http://perforce.freebsd.org/chv.cgi?CH=87394 Change 87394 by rwatson@rwatson_peppercorn on 2005/11/28 23:57:55 Apply similar changes to audit_control parsing as previously applied to audit_class: handle comments without terminating parsing, universally use (-1) as the return value for errors. Distinguish EOF and an error reading a configuration file. Affected files ... .. //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#6 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#6 (text+ko) ==== @@ -68,22 +68,33 @@ return (0); /* Error */ } - /* Search for the line beginning with the given name. */ - while (fgets(linestr, AU_LINE_MAX, fp) != NULL) { - /* Remove trailing new line character. */ - if ((nl = strrchr(linestr, '\n')) != NULL) - *nl = '\0'; + while (1) { + if (fgets(linestr, AU_LINE_MAX, fp) == NULL) { + pthread_mutex_unlock(&mutex); + if (ferror(fp)) + return (-1); + return (0); + } + + if (linestr[0] != '#') + break; + } + + /* Remove trailing new line character. */ + if ((nl = strrchr(linestr, '\n')) != NULL) + *nl = '\0'; - tokptr = linestr; - if ((type = strtok_r(tokptr, delim, &last)) != NULL) { - if (!strcmp(name, type)) { - /* Found matching name. */ - *str = strtok_r(NULL, delim, &last); - pthread_mutex_unlock(&mutex); - if (*str == NULL) - return (1); /* Parse error in file */ - return (0); /* Success */ + tokptr = linestr; + if ((type = strtok_r(tokptr, delim, &last)) != NULL) { + if (!strcmp(name, type)) { + /* Found matching name. */ + *str = strtok_r(NULL, delim, &last); + pthread_mutex_unlock(&mutex); + if (*str == NULL) { + errno = EINVAL; + return (-1); /* Parse error in file */ } + return (0); /* Success */ } } @@ -150,7 +161,7 @@ pthread_mutex_unlock(&mutex); - if (getstrfromtype(DIR_CONTROL_ENTRY, &dir) == 1) + if (getstrfromtype(DIR_CONTROL_ENTRY, &dir) < 0) return (-3); if (dir == NULL) @@ -179,7 +190,7 @@ return (-2); } - if (getstrfromtype(MINFREE_CONTROL_ENTRY, &min) == 1) + if (getstrfromtype(MINFREE_CONTROL_ENTRY, &min) < 0) return (-3); if (min == NULL) @@ -205,7 +216,7 @@ return (-2); } - if (getstrfromtype(FLAGS_CONTROL_ENTRY, &str) == 1) + if (getstrfromtype(FLAGS_CONTROL_ENTRY, &str) < 0) return (-3); if (str == NULL) @@ -234,7 +245,7 @@ return (-2); } - if (getstrfromtype(NA_CONTROL_ENTRY, &str) == 1) + if (getstrfromtype(NA_CONTROL_ENTRY, &str) < 0) return (-3); if (str == NULL)