Skip to contentSkip to conversation

mangle: check for end of string on every iteration

PATCH Applied Dave Reisner 2 participants 2 messages May 13, 2012 – May 15, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 lib/mangle.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/mangle.c +5 -4
index e1b4814..656918c 100644
@@ -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;
Signature · 1 line
1.7.10.2
maintainer Applied
#1 lore raw
Quoted 2 lines · Dave Reisner

Checking for the null byte at the end of the string only conditionally leads to segfaults, evidenced by mount helpers crashing on writes to

Ah.. sorry.

Quoted 7 lines

/run/mount/utab. Simply check for the null on each iteration, and append a null byte to the mangled string before breaking.

---
 lib/mangle.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Applied, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com