From 7a539b29af600e1adb1f48f4772a41c2e5e95e42 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 5 Aug 2010 13:14:58 +0200 Subject: [PATCH] lib: fix mange() and unmangle() to handle NULL Signed-off-by: Karel Zak --- lib/mangle.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/mangle.c b/lib/mangle.c index c40e67ba..e320cfb7 100644 --- a/lib/mangle.c +++ b/lib/mangle.c @@ -21,6 +21,9 @@ char *mangle(const char *s) char *ss, *sp; int n; + if (!s) + return NULL; + n = strlen(s); ss = sp = malloc(4*n+1); if (!sp) @@ -48,6 +51,9 @@ void unmangle_to_buffer(const char *s, char *buf, size_t len) { size_t sz = 0; + if (!s) + return; + while(*s && sz < len - 1) { if (*s == '\\' && sz + 4 < len - 1 && isoctal(s[1]) && isoctal(s[2]) && isoctal(s[3])) { @@ -79,6 +85,9 @@ char *unmangle(const char *s) const char *end; size_t sz; + if (!s) + return NULL; + end = skip_nonspaces(s); sz = end - s + 1; -- 2.39.5