From: Daan De Meyer Date: Thu, 23 Feb 2023 13:24:56 +0000 (+0100) Subject: chase-symlinks: Return "." as path from chase_symlinks_at() instead of NULL X-Git-Tag: v254-rc1~1110^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7bf4057d795c84392fd90520460484d2560bce09;p=thirdparty%2Fsystemd.git chase-symlinks: Return "." as path from chase_symlinks_at() instead of NULL --- diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c index 46e4e7ed7a8..bab5a5b2864 100644 --- a/src/basic/chase-symlinks.c +++ b/src/basic/chase-symlinks.c @@ -215,7 +215,7 @@ int chase_symlinks_at( return -errno; if (flags & CHASE_TRAIL_SLASH) - append_trail_slash = endswith(buffer, "/") || endswith(buffer, "/."); + append_trail_slash = ENDSWITH_SET(buffer, "/", "/."); for (todo = buffer;;) { _cleanup_free_ char *first = NULL; @@ -380,8 +380,15 @@ int chase_symlinks_at( close_and_replace(fd, child); } - if (ret_path) + if (ret_path) { + if (!done) { + done = strdup(append_trail_slash ? "./" : "."); + if (!done) + return -ENOMEM; + } + *ret_path = TAKE_PTR(done); + } if (ret_fd) { /* Return the O_PATH fd we currently are looking to the caller. It can translate it to a @@ -400,6 +407,12 @@ chased_one: if (ret_path) { const char *e; + if (!done) { + done = strdup(append_trail_slash ? "./" : "."); + if (!done) + return -ENOMEM; + } + /* todo may contain slashes at the beginning. */ r = path_find_first_component(&todo, /* accept_dot_dot= */ true, &e); if (r < 0) @@ -489,6 +502,12 @@ int chase_symlinks( if (!q) return -ENOMEM; + path_simplify(q); + + if (FLAGS_SET(flags, CHASE_TRAIL_SLASH) && ENDSWITH_SET(path, "/", "/.")) + if (!strextend(&q, "/")) + return -ENOMEM; + *ret_path = TAKE_PTR(q); }