Date: Mon, 28 Nov 2005 23:58:22 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 87394 for review Message-ID: <200511282358.jASNwMdd031220@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200511282358.jASNwMdd031220>