From 6d8690ecd34a6c9450e78e242e07b1a4479d6d27 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 16 Apr 2024 01:28:20 +0800 Subject: [PATCH 1/3] shared/vpick: align function args correctly, add missing assertion --- src/shared/vpick.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/shared/vpick.c b/src/shared/vpick.c index 6f15a7070d1..5e2b34e7b08 100644 --- a/src/shared/vpick.c +++ b/src/shared/vpick.c @@ -141,6 +141,7 @@ static int pin_choice( assert(toplevel_fd >= 0 || toplevel_fd == AT_FDCWD); assert(inode_path); assert(filter); + assert(ret); toplevel_path = strempty(toplevel_path); @@ -271,6 +272,7 @@ static int make_choice( assert(toplevel_fd >= 0 || toplevel_fd == AT_FDCWD); assert(inode_path); assert(filter); + assert(ret); toplevel_path = strempty(toplevel_path); @@ -486,12 +488,13 @@ static int make_choice( ret); } -int path_pick(const char *toplevel_path, - int toplevel_fd, - const char *path, - const PickFilter *filter, - PickFlags flags, - PickResult *ret) { +int path_pick( + const char *toplevel_path, + int toplevel_fd, + const char *path, + const PickFilter *filter, + PickFlags flags, + PickResult *ret) { _cleanup_free_ char *filter_bname = NULL, *dir = NULL, *parent = NULL, *fname = NULL; const char *filter_suffix, *enumeration_path; @@ -500,6 +503,8 @@ int path_pick(const char *toplevel_path, assert(toplevel_fd >= 0 || toplevel_fd == AT_FDCWD); assert(path); + assert(filter); + assert(ret); toplevel_path = strempty(toplevel_path); @@ -647,6 +652,7 @@ int path_pick_update_warn( assert(path); assert(*path); + assert(filter); /* This updates the first argument if needed! */ From ac68e6d691f6f00a24c6743363a0a887d9afbb52 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 16 Apr 2024 01:37:34 +0800 Subject: [PATCH 2/3] shared/vpick: drop unneeded strempty() prefix_roota() handles NULL root param gracefully. --- src/shared/vpick.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/shared/vpick.c b/src/shared/vpick.c index 5e2b34e7b08..c4c8accb376 100644 --- a/src/shared/vpick.c +++ b/src/shared/vpick.c @@ -143,8 +143,6 @@ static int pin_choice( assert(filter); assert(ret); - toplevel_path = strempty(toplevel_path); - if (inode_fd < 0 || FLAGS_SET(flags, PICK_RESOLVE)) { r = chaseat(toplevel_fd, inode_path, @@ -274,8 +272,6 @@ static int make_choice( assert(filter); assert(ret); - toplevel_path = strempty(toplevel_path); - if (inode_fd < 0) { r = chaseat(toplevel_fd, inode_path, CHASE_AT_RESOLVE_IN_ROOT, NULL, &inode_fd); if (r < 0) @@ -506,8 +502,6 @@ int path_pick( assert(filter); assert(ret); - toplevel_path = strempty(toplevel_path); - /* Given a path, resolve .v/ subdir logic (if used!), and returns the choice made. This supports * three ways to be called: * From c694419a51c573ff268a891a78758e5b05fc7824 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 16 Apr 2024 01:29:27 +0800 Subject: [PATCH 3/3] shared/vpick: add missing condition on ret_result Fixes #32285 --- src/shared/vpick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/vpick.c b/src/shared/vpick.c index c4c8accb376..1870fb97ef7 100644 --- a/src/shared/vpick.c +++ b/src/shared/vpick.c @@ -658,7 +658,9 @@ int path_pick_update_warn( &result); if (r == -ENOENT) { log_debug("Path '%s' doesn't exist, leaving as is.", *path); - *ret_result = PICK_RESULT_NULL; + + if (ret_result) + *ret_result = PICK_RESULT_NULL; return 0; } if (r < 0)