Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Nov 2005 22:07:02 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 87385 for review
Message-ID:  <200511282207.jASM72W7024489@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=87385

Change 87385 by rwatson@rwatson_peppercorn on 2005/11/28 22:07:01

	Make the class file parser a little more flexible and correct:
	when a comment is encountered in getauclassent(), don't abort
	parsing, just skip to the next line.  Implement getauclassnam()
	using getauclassent() to fix the same bug there.  This parser
	could be further improved.

Affected files ...

.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#5 edit

Differences ...

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#5 (text+ko) ====

@@ -146,10 +146,18 @@
 		return (NULL);
 	}
 
-	if (fgets(linestr, AU_LINE_MAX, fp) == NULL) {
-		pthread_mutex_unlock(&mutex);
-		return (NULL);
+	/*
+	 * Read until next non-comment line is found, or EOF.
+	 */
+	while (1) {
+		if (fgets(linestr, AU_LINE_MAX, fp) == NULL) {
+			pthread_mutex_unlock(&mutex);
+			return (NULL);
+		}
+		if (linestr[0] != '#')
+			break;
 	}
+
 	/* Remove trailing new line character. */
 	if ((nl = strrchr(linestr, '\n')) != NULL)
 		*nl = '\0';
@@ -180,7 +188,6 @@
 getauclassnam(const char *name)
 {
 	struct au_class_ent *c;
-	char *nl;
 
 	if (name == NULL)
 		return (NULL);
@@ -201,24 +208,16 @@
 		return (NULL);
 	}
 
-	while(fgets(linestr, AU_LINE_MAX, fp) != NULL) {
-		/* Remove trailing new line character */
-		if ((nl = strrchr(linestr, '\n')) != NULL)
-			*nl = '\0';
-
-		/* parse tokptr to au_class_ent components */
-		if (classfromstr(linestr, delim, c) != NULL) {
-			if (!strcmp(name, c->ac_name)) {
-				pthread_mutex_unlock(&mutex);
-				return (c);
-			}
+	while ((c = getauclassent()) != NULL) {
+		if (strcmp(name, c->ac_name) == 0) {
+			pthread_mutex_unlock(&mutex);
+			return (c);
 		}
+		free_au_class_ent(c);
 	}
 
-	free_au_class_ent(c);
 	pthread_mutex_unlock(&mutex);
 	return (NULL);
-
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200511282207.jASM72W7024489>