]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: fix segfault
authorMarc-Antoine Perennou <Marc-Antoine@Perennou.com>
Mon, 18 Jul 2011 17:37:22 +0000 (19:37 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Jul 2011 21:46:45 +0000 (23:46 +0200)
An element declared as size_t cannot be detected as negative (len < 0)
is always false.
This can lead to an infinite loop causing a segmentation fault.
Check if len is equal to -1 or -2 instead

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
sys-utils/dmesg.c

index 867581d814354ee3cae8549dcd880afeeefb66a0..d7cf95ba0beb67c049fe63d1e9478fd7562e2276 100644 (file)
@@ -367,7 +367,7 @@ static void safe_fwrite(const char *buf, size_t size, FILE *out)
                if (len == 0)                           /* L'\0' */
                        return;
 
-               if (len < 0) {                          /* invalid sequence */
+               if (len == (size_t)-1 || len == (size_t)-2) {           /* invalid sequence */
                        memset(&s, 0, sizeof (s));
                        len = hex = 1;