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
This commit is contained in:
parent
822c3837f9
commit
28355a36da
@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *);
|
|||||||
*/
|
*/
|
||||||
static char *busybox_fullpath()
|
static char *busybox_fullpath()
|
||||||
{
|
{
|
||||||
char proc[256];
|
return xreadlink("/proc/self/exe");
|
||||||
|
|
||||||
sprintf(proc, "/proc/%d/exe", getpid());
|
|
||||||
return xreadlink(proc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create (sym)links for each applet */
|
/* create (sym)links for each applet */
|
||||||
|
@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
|
|||||||
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
|
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
|
||||||
} else if (S_ISLNK(statbuf->st_mode)) {
|
} else if (S_ISLNK(statbuf->st_mode)) {
|
||||||
char *lpath = xreadlink(real_name);
|
char *lpath = xreadlink(real_name);
|
||||||
|
if (!lpath) /* Already printed err msg inside xreadlink() */
|
||||||
|
return ( FALSE);
|
||||||
header.typeflag = SYMTYPE;
|
header.typeflag = SYMTYPE;
|
||||||
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
||||||
free(lpath);
|
free(lpath);
|
||||||
|
@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *);
|
|||||||
*/
|
*/
|
||||||
static char *busybox_fullpath()
|
static char *busybox_fullpath()
|
||||||
{
|
{
|
||||||
char proc[256];
|
return xreadlink("/proc/self/exe");
|
||||||
|
|
||||||
sprintf(proc, "/proc/%d/exe", getpid());
|
|
||||||
return xreadlink(proc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create (sym)links for each applet */
|
/* create (sym)links for each applet */
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* xreadlink.c - safe implementation of readlink
|
* xreadlink.c - safe implementation of readlink.
|
||||||
|
* Returns a NULL on failure...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -22,8 +23,10 @@ extern char *xreadlink(const char *path)
|
|||||||
do {
|
do {
|
||||||
buf = xrealloc(buf, bufsize += GROWBY);
|
buf = xrealloc(buf, bufsize += GROWBY);
|
||||||
readsize = readlink(path, buf, bufsize); /* 1st try */
|
readsize = readlink(path, buf, bufsize); /* 1st try */
|
||||||
if (readsize == -1)
|
if (readsize == -1) {
|
||||||
perror_msg("%s:%s", applet_name, path);
|
perror_msg("%s:%s", applet_name, path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (bufsize < readsize + 1);
|
while (bufsize < readsize + 1);
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv)
|
|||||||
show_usage();
|
show_usage();
|
||||||
|
|
||||||
buf = xreadlink(argv[1]);
|
buf = xreadlink(argv[1]);
|
||||||
|
if (!buf)
|
||||||
|
return EXIT_FAILURE;
|
||||||
puts(buf);
|
puts(buf);
|
||||||
#ifdef BB_FEATURE_CLEAN_UP
|
#ifdef BB_FEATURE_CLEAN_UP
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv)
|
|||||||
show_usage();
|
show_usage();
|
||||||
|
|
||||||
buf = xreadlink(argv[1]);
|
buf = xreadlink(argv[1]);
|
||||||
|
if (!buf)
|
||||||
|
return EXIT_FAILURE;
|
||||||
puts(buf);
|
puts(buf);
|
||||||
#ifdef BB_FEATURE_CLEAN_UP
|
#ifdef BB_FEATURE_CLEAN_UP
|
||||||
free(buf);
|
free(buf);
|
||||||
|
2
tar.c
2
tar.c
@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
|
|||||||
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
|
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
|
||||||
} else if (S_ISLNK(statbuf->st_mode)) {
|
} else if (S_ISLNK(statbuf->st_mode)) {
|
||||||
char *lpath = xreadlink(real_name);
|
char *lpath = xreadlink(real_name);
|
||||||
|
if (!lpath) /* Already printed err msg inside xreadlink() */
|
||||||
|
return ( FALSE);
|
||||||
header.typeflag = SYMTYPE;
|
header.typeflag = SYMTYPE;
|
||||||
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
||||||
free(lpath);
|
free(lpath);
|
||||||
|
Loading…
Reference in New Issue
Block a user