]> granicus.if.org Git - procps-ng/commitdiff
watch: Correctly process [m Remove lib dependency
authorCraig Small <csmall@enc.com.au>
Tue, 1 Sep 2015 11:28:07 +0000 (21:28 +1000)
committerCraig Small <csmall@enc.com.au>
Wed, 14 Oct 2015 10:34:54 +0000 (21:34 +1100)
The commit referenced below made the ANSI sequence
[m be interpreted as [0m However this change was put
in the incorrect place and would reference an undefined
pointer, causing a crash. Thanks to Jimmy Theis for the
second heads-up.

watch doesn't need any libprocps functions so it is no
longer linked to them.

References:
 commit a5937e4e943eaf28b378a318566d6968f2b167be
 https://www.freelists.org/post/procps/watch-crashes-but-its-not-the-latest-commit-fault
 https://www.freelists.org/post/procps/Segmentation-fault-in-watch-3311

Signed-off-by: Craig Small <csmall@enc.com.au>
Ported-by: Jim Warner <james.warner@comcast.net>
From original:
commit 99fa7f9f57f52afdf648584879f37980731215d5

Makefile.am
watch.c

index 38c0438b358f88ecc5f8aab08a5f1a5f2250bcb8..fa5ee7287f6d6738bdeccce2a3fbdb6f5ab820df 100644 (file)
@@ -96,7 +96,7 @@ dist_man_MANS += \
 slabtop_SOURCES = slabtop.c lib/strutils.c lib/fileutils.c
 slabtop_LDADD = $(LDADD) @NCURSES_LIBS@
 watch_SOURCES = watch.c lib/strutils.c lib/fileutils.c
-watch_LDADD = $(LDADD) @WATCH_NCURSES_LIBS@
+watch_LDADD = @WATCH_NCURSES_LIBS@
 top_top_SOURCES = \
        top/top.h \
        top/top.c \
diff --git a/watch.c b/watch.c
index b7dd4412df499b54f01841beefab184a49e6f73a..7b55eee1b7baf6bc5f4b80f2d0c44a93be497ac0 100644 (file)
--- a/watch.c
+++ b/watch.c
@@ -227,10 +227,12 @@ static void process_ansi(FILE * fp)
         * attributes to apply, but typically there are between 1 and 3.
         */
 
-       if (*endptr == '\0') set_ansi_attribute(0); /* [m treated as [0m */
 
-       for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1)
+       for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1) {
                set_ansi_attribute(strtol(numstart, &endptr, 10));
+        if (numstart == endptr)
+            set_ansi_attribute(0); /* [m treated as [0m */
+    }
 }
 
 static void __attribute__ ((__noreturn__)) do_exit(int status)