From: Karel Zak Date: Thu, 5 Aug 2010 11:14:58 +0000 (+0200) Subject: lib: fix mange() and unmangle() to handle NULL X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a539b29af600e1adb1f48f4772a41c2e5e95e42;p=util-linux lib: fix mange() and unmangle() to handle NULL Signed-off-by: Karel Zak --- 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;