summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner2012-05-13 21:14:49 +0200
committerKarel Zak2012-05-15 11:32:24 +0200
commitea178007eb63a528f27805c04b5246519b5ef61a (patch)
tree57693924a60f17ba72f1113098c27e25ec43c534
parentrev: mention tac(1) in 'SEE ALSO' man page section (diff)
downloadkernel-qcow2-util-linux-ea178007eb63a528f27805c04b5246519b5ef61a.tar.gz
kernel-qcow2-util-linux-ea178007eb63a528f27805c04b5246519b5ef61a.tar.xz
kernel-qcow2-util-linux-ea178007eb63a528f27805c04b5246519b5ef61a.zip
lib/mangle: check for end of string on every iteration
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>
-rw-r--r--lib/mangle.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/mangle.c b/lib/mangle.c
index e1b48149f..656918c4b 100644
--- a/lib/mangle.c
+++ b/lib/mangle.c
@@ -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;