]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-util: handle NULL inputs in last_path_component()
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Oct 2018 14:06:54 +0000 (16:06 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Nov 2018 17:09:01 +0000 (18:09 +0100)
src/basic/path-util.c
src/test/test-path-util.c

index eb64c886e6c340e5da0974e1d9defc5e8f2ad197..243771d9e45f0676443679443ecb03c008b0d929 100644 (file)
@@ -750,6 +750,9 @@ const char *last_path_component(const char *path) {
 
         unsigned l, k;
 
+        if (!path)
+                return NULL;
+
         l = k = strlen(path);
         if (l == 0) /* special case — an empty string */
                 return path;
index b5030ea494a081f6c005f702b91b16080fc85421..dd00f13905f432d5ceda1b24069b2669c3fcc1f6 100644 (file)
@@ -406,6 +406,7 @@ static void test_file_in_same_dir(void) {
 }
 
 static void test_last_path_component(void) {
+        assert_se(last_path_component(NULL) == NULL);
         assert_se(streq(last_path_component("a/b/c"), "c"));
         assert_se(streq(last_path_component("a/b/c/"), "c/"));
         assert_se(streq(last_path_component("/"), "/"));