summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/config/main.c')
-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