From: Lennart Poettering Date: Fri, 26 Oct 2018 14:06:54 +0000 (+0200) Subject: path-util: handle NULL inputs in last_path_component() X-Git-Tag: v240~175^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77e0a1b5e09d782a32f5144319f344cc77f5ab45;p=thirdparty%2Fsystemd.git path-util: handle NULL inputs in last_path_component() --- diff --git a/src/basic/path-util.c b/src/basic/path-util.c index eb64c886e6c..243771d9e45 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -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; diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index b5030ea494a..dd00f13905f 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -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("/"), "/"));