Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): fix undefined behavior in meta_oodate



details:   https://anonhg.NetBSD.org/src/rev/3aff4f624865
branches:  trunk
changeset: 958042:3aff4f624865
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 20 22:36:40 2020 +0000

description:
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.

diffstat:

 usr.bin/make/meta.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (31 lines):

diff -r 2c37e7784983 -r 3aff4f624865 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sun Dec 20 22:12:36 2020 +0000
+++ b/usr.bin/make/meta.c       Sun Dec 20 22:36:40 2020 +0000
@@ -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_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 @@
                                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';



Home | Main Index | Thread Index | Old Index