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>
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;