aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-05-02 17:08:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-05-02 17:08:29 +0200
commit15a357e5962634c94ee322fee4da897312090a89 (patch)
tree757286a47b38c0c405ab0c5b9aa82a0c87c3a22d
parenta4476eb6543505f8685b59b138cb868b32347d71 (diff)
downloadbusybox-w32-15a357e5962634c94ee322fee4da897312090a89.tar.gz
busybox-w32-15a357e5962634c94ee322fee4da897312090a89.tar.bz2
busybox-w32-15a357e5962634c94ee322fee4da897312090a89.zip
libbb: fix empty PATH components handling
function old new delta find_execable 81 86 +5 exists_execable 71 66 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/execable.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/libbb/execable.c b/libbb/execable.c
index 178a00a5f..a3caea6f9 100644
--- a/libbb/execable.c
+++ b/libbb/execable.c
@@ -30,6 +30,14 @@ int FAST_FUNC execable_file(const char *name)
30 */ 30 */
31char* FAST_FUNC find_execable(const char *filename, char **PATHp) 31char* FAST_FUNC find_execable(const char *filename, char **PATHp)
32{ 32{
33 /* About empty components in $PATH:
34 * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
35 * 8.3 Other Environment Variables - PATH
36 * A zero-length prefix is a legacy feature that indicates the current
37 * working directory. It appears as two adjacent colons ( "::" ), as an
38 * initial colon preceding the rest of the list, or as a trailing colon
39 * following the rest of the list.
40 */
33 char *p, *n; 41 char *p, *n;
34 42
35 p = *PATHp; 43 p = *PATHp;
@@ -37,14 +45,15 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp)
37 n = strchr(p, ':'); 45 n = strchr(p, ':');
38 if (n) 46 if (n)
39 *n++ = '\0'; 47 *n++ = '\0';
40 if (*p != '\0') { /* it's not a PATH="foo::bar" situation */ 48 p = concat_path_file(
41 p = concat_path_file(p, filename); 49 p[0] ? p : ".", /* handle "::" case */
42 if (execable_file(p)) { 50 filename
43 *PATHp = n; 51 );
44 return p; 52 if (execable_file(p)) {
45 } 53 *PATHp = n;
46 free(p); 54 return p;
47 } 55 }
56 free(p);
48 p = n; 57 p = n;
49 } /* on loop exit p == NULL */ 58 } /* on loop exit p == NULL */
50 return p; 59 return p;
@@ -60,11 +69,8 @@ int FAST_FUNC exists_execable(const char *filename)
60 char *tmp = path; 69 char *tmp = path;
61 char *ret = find_execable(filename, &tmp); 70 char *ret = find_execable(filename, &tmp);
62 free(path); 71 free(path);
63 if (ret) { 72 free(ret);
64 free(ret); 73 return ret != NULL;
65 return 1;
66 }
67 return 0;
68} 74}
69 75
70#if ENABLE_FEATURE_PREFER_APPLETS 76#if ENABLE_FEATURE_PREFER_APPLETS