]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mangle: check for end of string on every iteration
authorDave Reisner <dreisner@archlinux.org>
Sun, 13 May 2012 19:14:49 +0000 (15:14 -0400)
committerKarel Zak <kzak@redhat.com>
Tue, 15 May 2012 09:32:24 +0000 (11:32 +0200)
Checking for the null byte at the end of the string only conditionally
leads to segfaults, evidenced by mount helpers crashing on writes to
/run/mount/utab. Simply check for the null on each iteration, and append
a null byte to the mangled string before breaking.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
lib/mangle.c

index e1b48149f9731a75c926579a7b17ad1dda49b1a2..656918c4bbbe4da3ec1724d70ee4aeae414749eb 100644 (file)
@@ -31,16 +31,17 @@ char *mangle(const char *s)
        if (!sp)
                return NULL;
        while(1) {
+               if (!*s) {
+                       *sp = '\0';
+                       break;
+               }
                if (is_unwanted_char(*s)) {
                        *sp++ = '\\';
                        *sp++ = '0' + ((*s & 0300) >> 6);
                        *sp++ = '0' + ((*s & 070) >> 3);
                        *sp++ = '0' + (*s & 07);
-               } else {
+               } else
                        *sp++ = *s;
-                       if (!*s)
-                               break;
-               }
                s++;
        }
        return ss;