summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--applets/busybox.c5
-rw-r--r--archival/tar.c2
-rw-r--r--busybox.c5
-rw-r--r--libbb/xreadlink.c9
-rw-r--r--miscutils/readlink.c2
-rw-r--r--readlink.c2
-rw-r--r--tar.c2
7 files changed, 16 insertions, 11 deletions
diff --git a/applets/busybox.c b/applets/busybox.c
index badd53d..41b6069 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *);
*/
static char *busybox_fullpath()
{
- char proc[256];
-
- sprintf(proc, "/proc/%d/exe", getpid());
- return xreadlink(proc);
+ return xreadlink("/proc/self/exe");
}
/* create (sym)links for each applet */
diff --git a/archival/tar.c b/archival/tar.c
index eb085c7..135bfd1 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
} else if (S_ISLNK(statbuf->st_mode)) {
char *lpath = xreadlink(real_name);
+ if (!lpath) /* Already printed err msg inside xreadlink() */
+ return ( FALSE);
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
free(lpath);
diff --git a/busybox.c b/busybox.c
index badd53d..41b6069 100644
--- a/busybox.c
+++ b/busybox.c
@@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *);
*/
static char *busybox_fullpath()
{
- char proc[256];
-
- sprintf(proc, "/proc/%d/exe", getpid());
- return xreadlink(proc);
+ return xreadlink("/proc/self/exe");
}
/* create (sym)links for each applet */
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 66f63b8..932e487 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -1,5 +1,6 @@
/*
- * xreadlink.c - safe implementation of readlink
+ * xreadlink.c - safe implementation of readlink.
+ * Returns a NULL on failure...
*/
#include <stdio.h>
@@ -22,8 +23,10 @@ extern char *xreadlink(const char *path)
do {
buf = xrealloc(buf, bufsize += GROWBY);
readsize = readlink(path, buf, bufsize); /* 1st try */
- if (readsize == -1)
- perror_msg("%s:%s", applet_name, path);
+ if (readsize == -1) {
+ perror_msg("%s:%s", applet_name, path);
+ return NULL;
+ }
}
while (bufsize < readsize + 1);
diff --git a/miscutils/readlink.c b/miscutils/readlink.c
index 2266495..c46ebd1 100644
--- a/miscutils/readlink.c
+++ b/miscutils/readlink.c
@@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv)
show_usage();
buf = xreadlink(argv[1]);
+ if (!buf)
+ return EXIT_FAILURE;
puts(buf);
#ifdef BB_FEATURE_CLEAN_UP
free(buf);
diff --git a/readlink.c b/readlink.c
index 2266495..c46ebd1 100644
--- a/readlink.c
+++ b/readlink.c
@@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv)
show_usage();
buf = xreadlink(argv[1]);
+ if (!buf)
+ return EXIT_FAILURE;
puts(buf);
#ifdef BB_FEATURE_CLEAN_UP
free(buf);
diff --git a/tar.c b/tar.c
index eb085c7..135bfd1 100644
--- a/tar.c
+++ b/tar.c
@@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
} else if (S_ISLNK(statbuf->st_mode)) {
char *lpath = xreadlink(real_name);
+ if (!lpath) /* Already printed err msg inside xreadlink() */
+ return ( FALSE);
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
free(lpath);