svn commit: r207594 - stable/7/usr.sbin/config

Warner Losh imp at FreeBSD.org
Tue May 4 04:02:43 UTC 2010


Author: imp
Date: Tue May  4 04:02:43 2010
New Revision: 207594
URL: http://svn.freebsd.org/changeset/base/207594

Log:
  MFC r188214 (by wkoszek):
  
     Make config -x <kernel> only return non-zero characters,
     so that:
          config -x <kernel> | grep <something>
     just works.
  
     Reported by:    Danny Braniss <danny at cs.huji.ac.il>

Modified:
  stable/7/usr.sbin/config/main.c
Directory Properties:
  stable/7/usr.sbin/config/   (props changed)

Modified: stable/7/usr.sbin/config/main.c
==============================================================================
--- stable/7/usr.sbin/config/main.c	Tue May  4 03:56:25 2010	(r207593)
+++ stable/7/usr.sbin/config/main.c	Tue May  4 04:02:43 2010	(r207594)
@@ -667,7 +667,7 @@ kernconfdump(const char *file)
 	struct stat st;
 	FILE *fp, *pp;
 	int error, len, osz, r;
-	unsigned int off, size;
+	unsigned int i, off, size;
 	char *cmd, *o;
 
 	r = open(file, O_RDONLY);
@@ -705,7 +705,18 @@ kernconfdump(const char *file)
 	r = fseek(fp, off, SEEK_CUR);
 	if (r != 0)
 		errx(EXIT_FAILURE, "fseek() failed");
-	while ((r = fgetc(fp)) != EOF && size-- > 0)
+	for (i = 0; i < size - 1; i++) {
+		r = fgetc(fp);
+		if (r == EOF)
+			break;
+		/* 
+		 * If '\0' is present in the middle of the configuration
+		 * string, this means something very weird is happening.
+		 * Make such case very visible.
+		 */
+		assert(r != '\0' && ("Char present in the configuration "
+		    "string mustn't be equal to 0"));
 		fputc(r, stdout);
+	}
 	fclose(fp);
 }


More information about the svn-src-all mailing list