diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-11 16:19:28 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-11 16:19:28 +0000 |
commit | 661a976a4fe1564096942a548031bcc1a4915057 (patch) | |
tree | c13da1537be3327e041fac86d9fdce68de70298a | |
parent | 5614b1d6f3e1a5c137f431999fbbb38ce8cb8db8 (diff) | |
download | busybox-w32-661a976a4fe1564096942a548031bcc1a4915057.tar.gz busybox-w32-661a976a4fe1564096942a548031bcc1a4915057.tar.bz2 busybox-w32-661a976a4fe1564096942a548031bcc1a4915057.zip |
syslogd: fix "readpath bug" by using readlink instead
libbb: rename xgetcwd and xreadlink
git-svn-id: svn://busybox.net/trunk/busybox@17854 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | applets/busybox.c | 2 | ||||
-rw-r--r-- | archival/tar.c | 4 | ||||
-rw-r--r-- | coreutils/ls.c | 2 | ||||
-rw-r--r-- | coreutils/pwd.c | 3 | ||||
-rw-r--r-- | coreutils/stat.c | 4 | ||||
-rw-r--r-- | debianutils/readlink.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/copy_file.c | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 2 | ||||
-rw-r--r-- | libbb/simplify_path.c | 2 | ||||
-rw-r--r-- | libbb/xgetcwd.c | 4 | ||||
-rw-r--r-- | libbb/xreadlink.c | 2 | ||||
-rw-r--r-- | shell/hush.c | 4 | ||||
-rw-r--r-- | shell/lash.c | 6 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 41 |
15 files changed, 46 insertions, 38 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index 99af9ca02..0387d79b7 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -92,7 +92,7 @@ int busybox_main(int argc, char **argv) | |||
92 | 92 | ||
93 | /* link */ | 93 | /* link */ |
94 | // XXX: FIXME: this is broken. Why not just use argv[0] ? | 94 | // XXX: FIXME: this is broken. Why not just use argv[0] ? |
95 | busybox = xreadlink("/proc/self/exe"); | 95 | busybox = xmalloc_readlink_or_warn("/proc/self/exe"); |
96 | if (!busybox) | 96 | if (!busybox) |
97 | return 1; | 97 | return 1; |
98 | install_links(busybox, use_symbolic_links); | 98 | install_links(busybox, use_symbolic_links); |
diff --git a/archival/tar.c b/archival/tar.c index d8e36749e..57da0b6b8 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -273,8 +273,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo, | |||
273 | tbInfo->hlInfo->name, 0); | 273 | tbInfo->hlInfo->name, 0); |
274 | #endif | 274 | #endif |
275 | } else if (S_ISLNK(statbuf->st_mode)) { | 275 | } else if (S_ISLNK(statbuf->st_mode)) { |
276 | char *lpath = xreadlink(fileName); | 276 | char *lpath = xmalloc_readlink_or_warn(fileName); |
277 | if (!lpath) /* Already printed err msg inside xreadlink() */ | 277 | if (!lpath) |
278 | return FALSE; | 278 | return FALSE; |
279 | header.typeflag = SYMTYPE; | 279 | header.typeflag = SYMTYPE; |
280 | strncpy(header.linkname, lpath, sizeof(header.linkname)); | 280 | strncpy(header.linkname, lpath, sizeof(header.linkname)); |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 798bc8201..34fae5026 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -664,7 +664,7 @@ static int list_single(struct dnode *dn) | |||
664 | break; | 664 | break; |
665 | case LIST_SYMLINK: | 665 | case LIST_SYMLINK: |
666 | if (S_ISLNK(dn->dstat.st_mode)) { | 666 | if (S_ISLNK(dn->dstat.st_mode)) { |
667 | char *lpath = xreadlink(dn->fullname); | 667 | char *lpath = xmalloc_readlink_or_warn(dn->fullname); |
668 | if (!lpath) break; | 668 | if (!lpath) break; |
669 | printf(" -> "); | 669 | printf(" -> "); |
670 | #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR | 670 | #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR |
diff --git a/coreutils/pwd.c b/coreutils/pwd.c index b4599b4f3..d96f6a8e5 100644 --- a/coreutils/pwd.c +++ b/coreutils/pwd.c | |||
@@ -16,7 +16,8 @@ int pwd_main(int argc, char **argv) | |||
16 | { | 16 | { |
17 | char *buf; | 17 | char *buf; |
18 | 18 | ||
19 | if ((buf = xgetcwd(NULL)) != NULL) { | 19 | buf = xrealloc_getcwd_or_warn(NULL); |
20 | if (buf != NULL) { | ||
20 | puts(buf); | 21 | puts(buf); |
21 | fflush_stdout_and_exit(EXIT_SUCCESS); | 22 | fflush_stdout_and_exit(EXIT_SUCCESS); |
22 | } | 23 | } |
diff --git a/coreutils/stat.c b/coreutils/stat.c index ff14a1599..20ade9472 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -188,7 +188,7 @@ static void print_stat(char *pformat, size_t buf_len, char m, | |||
188 | case 'N': | 188 | case 'N': |
189 | strncat(pformat, "s", buf_len); | 189 | strncat(pformat, "s", buf_len); |
190 | if (S_ISLNK(statbuf->st_mode)) { | 190 | if (S_ISLNK(statbuf->st_mode)) { |
191 | char *linkname = xreadlink(filename); | 191 | char *linkname = xmalloc_readlink_or_warn(filename); |
192 | if (linkname == NULL) { | 192 | if (linkname == NULL) { |
193 | bb_perror_msg("cannot read symbolic link '%s'", filename); | 193 | bb_perror_msg("cannot read symbolic link '%s'", filename); |
194 | return; | 194 | return; |
@@ -477,7 +477,7 @@ static int do_stat(char const *filename, char const *format) | |||
477 | pw_ent = getpwuid(statbuf.st_uid); | 477 | pw_ent = getpwuid(statbuf.st_uid); |
478 | 478 | ||
479 | if (S_ISLNK(statbuf.st_mode)) | 479 | if (S_ISLNK(statbuf.st_mode)) |
480 | linkname = xreadlink(filename); | 480 | linkname = xmalloc_readlink_or_warn(filename); |
481 | if (linkname) | 481 | if (linkname) |
482 | printf(" File: \"%s\" -> \"%s\"\n", filename, linkname); | 482 | printf(" File: \"%s\" -> \"%s\"\n", filename, linkname); |
483 | else | 483 | else |
diff --git a/debianutils/readlink.c b/debianutils/readlink.c index 8f9cfe431..1a2c1efb7 100644 --- a/debianutils/readlink.c +++ b/debianutils/readlink.c | |||
@@ -38,7 +38,7 @@ int readlink_main(int argc, char **argv) | |||
38 | if (opt) { | 38 | if (opt) { |
39 | buf = realpath(fname, bb_common_bufsiz1); | 39 | buf = realpath(fname, bb_common_bufsiz1); |
40 | } else { | 40 | } else { |
41 | buf = xreadlink(fname); | 41 | buf = xmalloc_readlink_or_warn(fname); |
42 | } | 42 | } |
43 | 43 | ||
44 | if (!buf) | 44 | if (!buf) |
diff --git a/include/libbb.h b/include/libbb.h index 218a1935c..077b65840 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -258,8 +258,8 @@ extern int ndelay_off(int fd); | |||
258 | extern DIR *xopendir(const char *path); | 258 | extern DIR *xopendir(const char *path); |
259 | extern DIR *warn_opendir(const char *path); | 259 | extern DIR *warn_opendir(const char *path); |
260 | 260 | ||
261 | char *xgetcwd(char *cwd); | 261 | char *xrealloc_getcwd_or_warn(char *cwd); |
262 | char *xreadlink(const char *path); | 262 | char *xmalloc_readlink_or_warn(const char *path); |
263 | char *xmalloc_realpath(const char *path); | 263 | char *xmalloc_realpath(const char *path); |
264 | extern void xstat(const char *filename, struct stat *buf); | 264 | extern void xstat(const char *filename, struct stat *buf); |
265 | extern pid_t spawn(char **argv); | 265 | extern pid_t spawn(char **argv); |
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 632064eaa..bd785b71c 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -233,7 +233,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
233 | } else if (S_ISLNK(source_stat.st_mode)) { | 233 | } else if (S_ISLNK(source_stat.st_mode)) { |
234 | char *lpath; | 234 | char *lpath; |
235 | 235 | ||
236 | lpath = xreadlink(source); | 236 | lpath = xmalloc_readlink_or_warn(source); |
237 | if (symlink(lpath, dest) < 0) { | 237 | if (symlink(lpath, dest) < 0) { |
238 | bb_perror_msg("cannot create symlink '%s'", dest); | 238 | bb_perror_msg("cannot create symlink '%s'", dest); |
239 | free(lpath); | 239 | free(lpath); |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 937d70d1f..16256f726 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -1090,7 +1090,7 @@ static void parse_prompt(const char *prmt_ptr) | |||
1090 | size_t cur_prmt_len = 0; | 1090 | size_t cur_prmt_len = 0; |
1091 | char flg_not_length = '['; | 1091 | char flg_not_length = '['; |
1092 | char *prmt_mem_ptr = xzalloc(1); | 1092 | char *prmt_mem_ptr = xzalloc(1); |
1093 | char *pwd_buf = xgetcwd(0); | 1093 | char *pwd_buf = xrealloc_getcwd_or_warn(NULL); |
1094 | char buf2[PATH_MAX + 1]; | 1094 | char buf2[PATH_MAX + 1]; |
1095 | char buf[2]; | 1095 | char buf[2]; |
1096 | char c; | 1096 | char c; |
diff --git a/libbb/simplify_path.c b/libbb/simplify_path.c index b714c66b6..7e68e3911 100644 --- a/libbb/simplify_path.c +++ b/libbb/simplify_path.c | |||
@@ -16,7 +16,7 @@ char *bb_simplify_path(const char *path) | |||
16 | if (path[0] == '/') | 16 | if (path[0] == '/') |
17 | start = xstrdup(path); | 17 | start = xstrdup(path); |
18 | else { | 18 | else { |
19 | s = xgetcwd(NULL); | 19 | s = xrealloc_getcwd_or_warn(NULL); |
20 | start = concat_path_file(s, path); | 20 | start = concat_path_file(s, path); |
21 | free(s); | 21 | free(s); |
22 | } | 22 | } |
diff --git a/libbb/xgetcwd.c b/libbb/xgetcwd.c index 0ac450d3b..ec1d8f7a4 100644 --- a/libbb/xgetcwd.c +++ b/libbb/xgetcwd.c | |||
@@ -18,7 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | char * | 20 | char * |
21 | xgetcwd(char *cwd) | 21 | xrealloc_getcwd_or_warn(char *cwd) |
22 | { | 22 | { |
23 | char *ret; | 23 | char *ret; |
24 | unsigned path_max; | 24 | unsigned path_max; |
@@ -26,7 +26,7 @@ xgetcwd(char *cwd) | |||
26 | path_max = (unsigned) PATH_MAX; | 26 | path_max = (unsigned) PATH_MAX; |
27 | path_max += 2; /* The getcwd docs say to do this. */ | 27 | path_max += 2; /* The getcwd docs say to do this. */ |
28 | 28 | ||
29 | if (cwd==0) | 29 | if (cwd == NULL) |
30 | cwd = xmalloc(path_max); | 30 | cwd = xmalloc(path_max); |
31 | 31 | ||
32 | while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) { | 32 | while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) { |
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index fb67cdef1..18a8b9467 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c | |||
@@ -11,7 +11,7 @@ | |||
11 | * yourself. You have been warned. | 11 | * yourself. You have been warned. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | char *xreadlink(const char *path) | 14 | char *xmalloc_readlink_or_warn(const char *path) |
15 | { | 15 | { |
16 | enum { GROWBY = 80 }; /* how large we will grow strings by */ | 16 | enum { GROWBY = 80 }; /* how large we will grow strings by */ |
17 | 17 | ||
diff --git a/shell/hush.c b/shell/hush.c index 573724075..7658aebed 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -423,8 +423,8 @@ static const struct built_in_command bltins[] = { | |||
423 | static const char *set_cwd(void) | 423 | static const char *set_cwd(void) |
424 | { | 424 | { |
425 | if (cwd == bb_msg_unknown) | 425 | if (cwd == bb_msg_unknown) |
426 | cwd = NULL; /* xgetcwd(arg) called free(arg) */ | 426 | cwd = NULL; /* xrealloc_getcwd_or_warn(arg) called free(arg) */ |
427 | cwd = xgetcwd((char *)cwd); | 427 | cwd = xrealloc_getcwd_or_warn((char *)cwd); |
428 | if (!cwd) | 428 | if (!cwd) |
429 | cwd = bb_msg_unknown; | 429 | cwd = bb_msg_unknown; |
430 | return cwd; | 430 | return cwd; |
diff --git a/shell/lash.c b/shell/lash.c index 502e0d829..09067fda0 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -217,7 +217,7 @@ static int builtin_cd(struct child_prog *child) | |||
217 | bb_perror_msg("cd: %s", newdir); | 217 | bb_perror_msg("cd: %s", newdir); |
218 | return EXIT_FAILURE; | 218 | return EXIT_FAILURE; |
219 | } | 219 | } |
220 | cwd = xgetcwd((char *)cwd); | 220 | cwd = xrealloc_getcwd_or_warn((char *)cwd); |
221 | if (!cwd) | 221 | if (!cwd) |
222 | cwd = bb_msg_unknown; | 222 | cwd = bb_msg_unknown; |
223 | return EXIT_SUCCESS; | 223 | return EXIT_SUCCESS; |
@@ -342,7 +342,7 @@ static int builtin_jobs(struct child_prog *child) | |||
342 | /* built-in 'pwd' handler */ | 342 | /* built-in 'pwd' handler */ |
343 | static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy) | 343 | static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy) |
344 | { | 344 | { |
345 | cwd = xgetcwd((char *)cwd); | 345 | cwd = xrealloc_getcwd_or_warn((char *)cwd); |
346 | if (!cwd) | 346 | if (!cwd) |
347 | cwd = bb_msg_unknown; | 347 | cwd = bb_msg_unknown; |
348 | puts(cwd); | 348 | puts(cwd); |
@@ -1569,7 +1569,7 @@ int lash_main(int argc_l, char **argv_l) | |||
1569 | } | 1569 | } |
1570 | 1570 | ||
1571 | /* initialize the cwd -- this is never freed...*/ | 1571 | /* initialize the cwd -- this is never freed...*/ |
1572 | cwd = xgetcwd(0); | 1572 | cwd = xrealloc_getcwd_or_warn(NULL); |
1573 | if (!cwd) | 1573 | if (!cwd) |
1574 | cwd = bb_msg_unknown; | 1574 | cwd = bb_msg_unknown; |
1575 | 1575 | ||
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 97ddf09b5..53290f1cc 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -24,9 +24,6 @@ | |||
24 | 24 | ||
25 | #define DEBUG 0 | 25 | #define DEBUG 0 |
26 | 26 | ||
27 | /* Path to the unix socket */ | ||
28 | static const char *dev_log_name; | ||
29 | |||
30 | /* Path for the file where all log messages are written */ | 27 | /* Path for the file where all log messages are written */ |
31 | static const char *logFilePath = "/var/log/messages"; | 28 | static const char *logFilePath = "/var/log/messages"; |
32 | static int logFD = -1; | 29 | static int logFD = -1; |
@@ -446,7 +443,6 @@ static void quit_signal(int sig) | |||
446 | { | 443 | { |
447 | timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0); | 444 | timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0); |
448 | puts("syslogd exiting"); | 445 | puts("syslogd exiting"); |
449 | unlink(dev_log_name); | ||
450 | if (ENABLE_FEATURE_IPC_SYSLOG) | 446 | if (ENABLE_FEATURE_IPC_SYSLOG) |
451 | ipcsyslog_cleanup(); | 447 | ipcsyslog_cleanup(); |
452 | exit(1); | 448 | exit(1); |
@@ -464,9 +460,9 @@ static void do_syslogd(void) ATTRIBUTE_NORETURN; | |||
464 | static void do_syslogd(void) | 460 | static void do_syslogd(void) |
465 | { | 461 | { |
466 | struct sockaddr_un sunx; | 462 | struct sockaddr_un sunx; |
467 | socklen_t addr_len; | ||
468 | int sock_fd; | 463 | int sock_fd; |
469 | fd_set fds; | 464 | fd_set fds; |
465 | char *dev_log_name; | ||
470 | 466 | ||
471 | /* Set up signal handlers */ | 467 | /* Set up signal handlers */ |
472 | signal(SIGINT, quit_signal); | 468 | signal(SIGINT, quit_signal); |
@@ -480,22 +476,33 @@ static void do_syslogd(void) | |||
480 | signal(SIGALRM, do_mark); | 476 | signal(SIGALRM, do_mark); |
481 | alarm(markInterval); | 477 | alarm(markInterval); |
482 | 478 | ||
483 | dev_log_name = xmalloc_realpath(_PATH_LOG); | ||
484 | if (!dev_log_name) | ||
485 | dev_log_name = _PATH_LOG; | ||
486 | |||
487 | /* Unlink old /dev/log (or object it points to) */ | ||
488 | unlink(dev_log_name); | ||
489 | |||
490 | memset(&sunx, 0, sizeof(sunx)); | 479 | memset(&sunx, 0, sizeof(sunx)); |
491 | sunx.sun_family = AF_UNIX; | 480 | sunx.sun_family = AF_UNIX; |
492 | strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path)); | 481 | strcpy(sunx.sun_path, "/dev/log"); |
482 | |||
483 | /* Unlink old /dev/log or object it points to. */ | ||
484 | /* (if it exists, bind will fail) */ | ||
485 | logmode = LOGMODE_NONE; | ||
486 | dev_log_name = xmalloc_readlink_or_warn("/dev/log"); | ||
487 | logmode = LOGMODE_STDIO; | ||
488 | if (dev_log_name) { | ||
489 | int fd = xopen(".", O_NONBLOCK); | ||
490 | xchdir("/dev"); | ||
491 | /* we do not check whether this is a link also */ | ||
492 | unlink(dev_log_name); | ||
493 | fchdir(fd); | ||
494 | close(fd); | ||
495 | safe_strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path)); | ||
496 | free(dev_log_name); | ||
497 | } else { | ||
498 | unlink("/dev/log"); | ||
499 | } | ||
500 | |||
493 | sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0); | 501 | sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0); |
494 | addr_len = sizeof(sunx.sun_family) + strlen(sunx.sun_path); | 502 | xbind(sock_fd, (struct sockaddr *) &sunx, sizeof(sunx)); |
495 | xbind(sock_fd, (struct sockaddr *) &sunx, addr_len); | ||
496 | 503 | ||
497 | if (chmod(dev_log_name, 0666) < 0) { | 504 | if (chmod("/dev/log", 0666) < 0) { |
498 | bb_perror_msg_and_die("cannot set permission on %s", dev_log_name); | 505 | bb_perror_msg_and_die("cannot set permission on /dev/log"); |
499 | } | 506 | } |
500 | if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) { | 507 | if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) { |
501 | ipcsyslog_init(); | 508 | ipcsyslog_init(); |