Module Name:    src
Committed By:   sjg
Date:           Wed Jun 22 21:13:13 UTC 2011

Modified Files:
        src/usr.bin/make: meta.c

Log Message:
After each strsep(&p) check that p is valid.
If not the .meta file is corrupted (build interrupted?)
issue a warning and declare target oodate.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/make/meta.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.19 src/usr.bin/make/meta.c:1.20
--- src/usr.bin/make/meta.c:1.19	Sat Jun 11 02:10:48 2011
+++ src/usr.bin/make/meta.c	Wed Jun 22 21:13:12 2011
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.19 2011/06/11 02:10:48 sjg Exp $ */
+/*      $NetBSD: meta.c,v 1.20 2011/06/22 21:13:12 sjg Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -809,6 +809,17 @@
  */
 #define LDIR_VNAME_FMT ".meta.%d.ldir"
 
+/*
+ * It is possible that a .meta file is corrupted,
+ * if we detect this we want to reproduce it.
+ * Setting oodate TRUE will have that effect.
+ */
+#define CHECK_VALID_META(p) if (!(p && *p)) { \
+    warnx("%s: %d: malformed", fname, lineno); \
+    oodate = TRUE; \
+    continue; \
+    }
+
 Boolean
 meta_oodate(GNode *gn, Boolean oodate)
 {
@@ -882,9 +893,11 @@
 	    lineno++;
 	    if (buf[x - 1] == '\n')
 		buf[x - 1] = '\0';
-	    else
+	    else {
 		warnx("%s: %d: line truncated at %u", fname, lineno, x);
-
+		oodate = TRUE;
+		break;
+	    }
 	    /* Find the start of the build monitor section. */
 	    if (!f) {
 		if (strncmp(buf, "-- filemon", 10) == 0) {
@@ -940,6 +953,7 @@
 		     * re-initialize 'latestdir' to any pre-saved
 		     * value for the current 'pid' and 'CWD' if none.
 		     */
+		    CHECK_VALID_META(p);
 		    pid = atoi(p);
 		    if (pid > 0 && pid != lastpid) {
 			char *ldir;
@@ -969,6 +983,8 @@
 		    break;
 		}
 
+		CHECK_VALID_META(p);
+
 		/* Process according to record type. */
 		switch (buf[0]) {
 		case 'X':		/* eXit */
@@ -1020,6 +1036,7 @@
 		    /* we want the target */
 		    if (strsep(&p, " ") == NULL)
 			continue;
+		    CHECK_VALID_META(p);
 		    /* 'L' and 'M' put single quotes around the args */
 		    if (*p == '\'') {
 			char *ep;

Reply via email to