diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-07 17:48:28 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-07 17:48:28 +0000 |
commit | 28355a36da6ad4d1b55ba9bb146fb0b6586e7edb (patch) | |
tree | d08439547c9b94e1d0211fb0de91e68fc3180fe4 | |
parent | 822c3837f95a355f90d25aaabeb2445bb5eb1bf0 (diff) | |
download | busybox-w32-28355a36da6ad4d1b55ba9bb146fb0b6586e7edb.tar.gz busybox-w32-28355a36da6ad4d1b55ba9bb146fb0b6586e7edb.tar.bz2 busybox-w32-28355a36da6ad4d1b55ba9bb146fb0b6586e7edb.zip |
Per some comments from Lars Kellogg-Stedman <lars@larsshack.org>,
make xreadlink() return NULL on failure, and make sure everyone
uses the interface correctly.
-Erik
-rw-r--r-- | applets/busybox.c | 5 | ||||
-rw-r--r-- | archival/tar.c | 2 | ||||
-rw-r--r-- | busybox.c | 5 | ||||
-rw-r--r-- | libbb/xreadlink.c | 9 | ||||
-rw-r--r-- | miscutils/readlink.c | 2 | ||||
-rw-r--r-- | readlink.c | 2 | ||||
-rw-r--r-- | tar.c | 2 |
7 files changed, 16 insertions, 11 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index badd53d79..41b6069ed 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *); | |||
37 | */ | 37 | */ |
38 | static char *busybox_fullpath() | 38 | static char *busybox_fullpath() |
39 | { | 39 | { |
40 | char proc[256]; | 40 | return xreadlink("/proc/self/exe"); |
41 | |||
42 | sprintf(proc, "/proc/%d/exe", getpid()); | ||
43 | return xreadlink(proc); | ||
44 | } | 41 | } |
45 | 42 | ||
46 | /* create (sym)links for each applet */ | 43 | /* create (sym)links for each applet */ |
diff --git a/archival/tar.c b/archival/tar.c index eb085c770..135bfd186 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name, | |||
922 | strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname)); | 922 | strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname)); |
923 | } else if (S_ISLNK(statbuf->st_mode)) { | 923 | } else if (S_ISLNK(statbuf->st_mode)) { |
924 | char *lpath = xreadlink(real_name); | 924 | char *lpath = xreadlink(real_name); |
925 | if (!lpath) /* Already printed err msg inside xreadlink() */ | ||
926 | return ( FALSE); | ||
925 | header.typeflag = SYMTYPE; | 927 | header.typeflag = SYMTYPE; |
926 | strncpy(header.linkname, lpath, sizeof(header.linkname)); | 928 | strncpy(header.linkname, lpath, sizeof(header.linkname)); |
927 | free(lpath); | 929 | free(lpath); |
@@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *); | |||
37 | */ | 37 | */ |
38 | static char *busybox_fullpath() | 38 | static char *busybox_fullpath() |
39 | { | 39 | { |
40 | char proc[256]; | 40 | return xreadlink("/proc/self/exe"); |
41 | |||
42 | sprintf(proc, "/proc/%d/exe", getpid()); | ||
43 | return xreadlink(proc); | ||
44 | } | 41 | } |
45 | 42 | ||
46 | /* create (sym)links for each applet */ | 43 | /* create (sym)links for each applet */ |
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 66f63b883..932e487a5 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * xreadlink.c - safe implementation of readlink | 2 | * xreadlink.c - safe implementation of readlink. |
3 | * Returns a NULL on failure... | ||
3 | */ | 4 | */ |
4 | 5 | ||
5 | #include <stdio.h> | 6 | #include <stdio.h> |
@@ -22,8 +23,10 @@ extern char *xreadlink(const char *path) | |||
22 | do { | 23 | do { |
23 | buf = xrealloc(buf, bufsize += GROWBY); | 24 | buf = xrealloc(buf, bufsize += GROWBY); |
24 | readsize = readlink(path, buf, bufsize); /* 1st try */ | 25 | readsize = readlink(path, buf, bufsize); /* 1st try */ |
25 | if (readsize == -1) | 26 | if (readsize == -1) { |
26 | perror_msg("%s:%s", applet_name, path); | 27 | perror_msg("%s:%s", applet_name, path); |
28 | return NULL; | ||
29 | } | ||
27 | } | 30 | } |
28 | while (bufsize < readsize + 1); | 31 | while (bufsize < readsize + 1); |
29 | 32 | ||
diff --git a/miscutils/readlink.c b/miscutils/readlink.c index 226649544..c46ebd108 100644 --- a/miscutils/readlink.c +++ b/miscutils/readlink.c | |||
@@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv) | |||
37 | show_usage(); | 37 | show_usage(); |
38 | 38 | ||
39 | buf = xreadlink(argv[1]); | 39 | buf = xreadlink(argv[1]); |
40 | if (!buf) | ||
41 | return EXIT_FAILURE; | ||
40 | puts(buf); | 42 | puts(buf); |
41 | #ifdef BB_FEATURE_CLEAN_UP | 43 | #ifdef BB_FEATURE_CLEAN_UP |
42 | free(buf); | 44 | free(buf); |
diff --git a/readlink.c b/readlink.c index 226649544..c46ebd108 100644 --- a/readlink.c +++ b/readlink.c | |||
@@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv) | |||
37 | show_usage(); | 37 | show_usage(); |
38 | 38 | ||
39 | buf = xreadlink(argv[1]); | 39 | buf = xreadlink(argv[1]); |
40 | if (!buf) | ||
41 | return EXIT_FAILURE; | ||
40 | puts(buf); | 42 | puts(buf); |
41 | #ifdef BB_FEATURE_CLEAN_UP | 43 | #ifdef BB_FEATURE_CLEAN_UP |
42 | free(buf); | 44 | free(buf); |
@@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name, | |||
922 | strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname)); | 922 | strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname)); |
923 | } else if (S_ISLNK(statbuf->st_mode)) { | 923 | } else if (S_ISLNK(statbuf->st_mode)) { |
924 | char *lpath = xreadlink(real_name); | 924 | char *lpath = xreadlink(real_name); |
925 | if (!lpath) /* Already printed err msg inside xreadlink() */ | ||
926 | return ( FALSE); | ||
925 | header.typeflag = SYMTYPE; | 927 | header.typeflag = SYMTYPE; |
926 | strncpy(header.linkname, lpath, sizeof(header.linkname)); | 928 | strncpy(header.linkname, lpath, sizeof(header.linkname)); |
927 | free(lpath); | 929 | free(lpath); |