From b972115c97b9ec1bb17ee4897da6b85d82727ca8 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 12 Apr 2014 17:17:49 -0400 Subject: path-util: also check for existence of binary when given absolute path In contrast to a filename-only argument, find_binary() did not actually check if an path exists, allowing the code to fail later on. This was OK, but it seems nicer to treat both paths identically. Also take advantage of path_make_absolute_cwd doing strdup() by itself if necessary to simplify. --- src/shared/path-util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/shared') diff --git a/src/shared/path-util.c b/src/shared/path-util.c index 1ad1084b2d..e35d7f8d67 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -427,15 +427,16 @@ int find_binary(const char *name, char **filename) { assert(name); if (strchr(name, '/')) { + if (access(name, X_OK) < 0) + return -errno; + if (filename) { char *p; - if (path_is_absolute(name)) - p = strdup(name); - else - p = path_make_absolute_cwd(name); + p = path_make_absolute_cwd(name); if (!p) return -ENOMEM; + *filename = p; } -- cgit v1.2.3-54-g00ecf