Module Name: src Committed By: rillig Date: Sun Dec 20 22:36:40 UTC 2020
Modified Files: src/usr.bin/make: meta.c Log Message: make(1): fix undefined behavior in meta_oodate Do not increment a null pointer. Do not assign to a variable twice in the same statement. To be fair, this may be safe because of the sequence point when the function is called, but anyway, it looks too close to undefined behavior. To generate a diff of this commit: cvs rdiff -u -r1.163 -r1.164 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.163 src/usr.bin/make/meta.c:1.164 --- src/usr.bin/make/meta.c:1.163 Sun Dec 20 22:12:36 2020 +++ src/usr.bin/make/meta.c Sun Dec 20 22:36:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.163 2020/12/20 22:12:36 rillig Exp $ */ +/* $NetBSD: meta.c,v 1.164 2020/12/20 22:36:40 rillig Exp $ */ /* * Implement 'meta' mode. @@ -820,9 +820,10 @@ meta_job_output(Job *job, char *cp, cons meta_prefix_len = strlen(meta_prefix); } if (strncmp(cp, meta_prefix, meta_prefix_len) == 0) { - cp = strchr(cp+1, '\n'); - if (!cp++) + cp = strchr(cp + 1, '\n'); + if (cp == NULL) return; + cp++; } } fprintf(pbm->mfp, "%s%s", cp, nl); @@ -1527,7 +1528,7 @@ meta_oodate(GNode *gn, Boolean oodate) warnx("%s: %d: line truncated at %u", fname, lineno, x); break; } - cp = strchr(++cp, '\n'); + cp = strchr(cp + 1, '\n'); } while (cp != NULL); if (buf[x - 1] == '\n') buf[x - 1] = '\0';