summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorwkoszek <wkoszek@FreeBSD.org>2009-02-06 00:50:21 +0000
committerwkoszek <wkoszek@FreeBSD.org>2009-02-06 00:50:21 +0000
commitd2a92510f277a68773979d7d6642ee5a51f86246 (patch)
treecd7cfe7c060965becc28970de0da2c18ceb5317a /usr.sbin/config
parentd40450f670fe8b484327eb239c097081f1f7205f (diff)
downloadFreeBSD-src-d2a92510f277a68773979d7d6642ee5a51f86246.zip
FreeBSD-src-d2a92510f277a68773979d7d6642ee5a51f86246.tar.gz
Make config -x <kernel> only return non-zero characters,
so that: config -x <kernel> | grep <something> just works. Reported by: Danny Braniss <danny@cs.huji.ac.il>
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/main.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 24b4396..58d6f2a 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -669,7 +669,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);
@@ -707,7 +707,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);
}
OpenPOWER on IntegriCloud