* [PATCH] mangle: check for end of string on every iteration
@ 2012-05-13 19:14 Dave Reisner
2012-05-15 9:33 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Dave Reisner @ 2012-05-13 19:14 UTC (permalink / raw)
To: util-linux; +Cc: 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
/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 | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/mangle.c b/lib/mangle.c
index e1b4814..656918c 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;
--
1.7.10.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mangle: check for end of string on every iteration
2012-05-13 19:14 [PATCH] mangle: check for end of string on every iteration Dave Reisner
@ 2012-05-15 9:33 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-05-15 9:33 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
On Sun, May 13, 2012 at 03:14:49PM -0400, Dave Reisner wrote:
> 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.
> /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 | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
Applied, thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-15 9:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-13 19:14 [PATCH] mangle: check for end of string on every iteration Dave Reisner
2012-05-15 9:33 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).