]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mangle: check for the NULL string argument
authorGaël PORTAY <gael.portay@collabora.com>
Fri, 20 Mar 2020 20:21:58 +0000 (16:21 -0400)
committerKarel Zak <kzak@redhat.com>
Fri, 15 May 2020 09:58:57 +0000 (11:58 +0200)
This patch prevents to call the function strlen() with a NULL string
argument that leads to a segmentation fault.

Signed-off-by: Gaël PORTAY <gael.portay@collabora.com>
include/mangle.h

index 0a4b60c1c8188b97dc66994e1451d02e1aa64a27..08c66cb47f5a80c484c3ffc0efc3da6420eb46a2 100644 (file)
@@ -14,12 +14,14 @@ extern char *unmangle(const char *s, const char **end);
 
 static inline void unmangle_string(char *s)
 {
-       unmangle_to_buffer(s, s, strlen(s) + 1);
+       if (s)
+               unmangle_to_buffer(s, s, strlen(s) + 1);
 }
 
 static inline void unhexmangle_string(char *s)
 {
-       unhexmangle_to_buffer(s, s, strlen(s) + 1);
+       if (s)
+               unhexmangle_to_buffer(s, s, strlen(s) + 1);
 }
 
 #endif /* UTIL_LINUX_MANGLE_H */