diff options
author | Eric Andersen | 2002-09-30 20:39:56 +0000 |
---|---|---|
committer | Eric Andersen | 2002-09-30 20:39:56 +0000 |
commit | 02e6ba91e887bd11146a57185b223582f56f3f09 (patch) | |
tree | cc1954165fe7e6efed1ba0dfa7d5c3aea97fffa5 | |
parent | a6f6e06107e69b79858acaa511c452a0a73cf207 (diff) | |
download | busybox-02e6ba91e887bd11146a57185b223582f56f3f09.zip busybox-02e6ba91e887bd11146a57185b223582f56f3f09.tar.gz |
Vodz' last_patch57:
Hi, Erik.
my_getpw(uid/gid) and applets used it have problem:
if username for uid not found, applets can`t detect it
(but code pessent). Also "%8ld " format is bad:
spaces not required (applets have self format
or spec format (tar applet) and overflow for "id" applet...)
This problem also pressent in stable version.
Patch for unstable in attach.
--w
vodz
-rw-r--r-- | archival/tar.c | 8 | ||||
-rw-r--r-- | coreutils/id.c | 7 | ||||
-rw-r--r-- | coreutils/logname.c | 3 | ||||
-rw-r--r-- | coreutils/whoami.c | 3 | ||||
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/my_getgrgid.c | 12 | ||||
-rw-r--r-- | libbb/my_getpwuid.c | 12 | ||||
-rw-r--r-- | procps/ps.c | 4 | ||||
-rw-r--r-- | sysklogd/logger.c | 6 |
9 files changed, 27 insertions, 32 deletions
diff --git a/archival/tar.c b/archival/tar.c index 0f0d4fd..88a815d 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -244,12 +244,10 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo, TAR_MAGIC_LEN + TAR_VERSION_LEN); /* Enter the user and group names (default to root if it fails) */ - my_getpwuid(header.uname, statbuf->st_uid); - if (!*header.uname) - strcpy(header.uname, "root"); - my_getgrgid(header.gname, statbuf->st_gid); - if (!*header.uname) + if (my_getpwuid(header.uname, statbuf->st_uid) == NULL) strcpy(header.uname, "root"); + if (my_getgrgid(header.gname, statbuf->st_gid) == NULL) + strcpy(header.gname, "root"); if (tbInfo->hlInfo) { /* This is a hard link */ diff --git a/coreutils/id.c b/coreutils/id.c index 85b288c..c7f6153 100644 --- a/coreutils/id.c +++ b/coreutils/id.c @@ -68,8 +68,7 @@ extern int id_main(int argc, char **argv) my_getgrgid(group, getegid()); } } else { - strncpy(user, argv[optind], 8); - user[8] = '\0'; + safe_strncpy(user, argv[optind], sizeof(user)); gid = my_getpwnamegid(user); my_getgrgid(group, gid); } @@ -78,12 +77,12 @@ extern int id_main(int argc, char **argv) grnam=my_getgrnam(group); if (no_group) { - if(name_not_number && user) + if(name_not_number) puts(user); else printf("%ld\n", pwnam); } else if (no_user) { - if(name_not_number && group) + if(name_not_number) puts(group); else printf("%ld\n", grnam); diff --git a/coreutils/logname.c b/coreutils/logname.c index 0924b24..3e10fba 100644 --- a/coreutils/logname.c +++ b/coreutils/logname.c @@ -32,8 +32,7 @@ extern int logname_main(int argc, char **argv) if (argc > 1) show_usage(); - my_getpwuid(user, geteuid()); - if (*user) { + if (my_getpwuid(user, geteuid())) { puts(user); return EXIT_SUCCESS; } diff --git a/coreutils/whoami.c b/coreutils/whoami.c index c3b1140..a9d6ecf 100644 --- a/coreutils/whoami.c +++ b/coreutils/whoami.c @@ -35,8 +35,7 @@ extern int whoami_main(int argc, char **argv) if (argc > 1) show_usage(); - my_getpwuid(user, uid); - if (*user) { + if (my_getpwuid(user, uid)) { puts(user); return EXIT_SUCCESS; } diff --git a/include/libbb.h b/include/libbb.h index 2fec93d..3b5f297 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -165,8 +165,8 @@ extern unsigned long parse_number(const char *numstr, * increases target size and is often not needed embedded systems. */ extern long my_getpwnam(const char *name); extern long my_getgrnam(const char *name); -extern void my_getpwuid(char *name, long uid); -extern void my_getgrgid(char *group, long gid); +extern char * my_getpwuid(char *name, long uid); +extern char * my_getgrgid(char *group, long gid); extern long my_getpwnamegid(const char *name); extern int device_open(char *device, int mode); diff --git a/libbb/my_getgrgid.c b/libbb/my_getgrgid.c index 88bafc9..5bf9051 100644 --- a/libbb/my_getgrgid.c +++ b/libbb/my_getgrgid.c @@ -27,15 +27,17 @@ /* gets a groupname given a gid */ -void my_getgrgid(char *group, long gid) +char * my_getgrgid(char *group, long gid) { struct group *mygroup; mygroup = getgrgid(gid); - if (mygroup==NULL) - sprintf(group, "%-8ld ", (long)gid); - else - strcpy(group, mygroup->gr_name); + if (mygroup==NULL) { + sprintf(group, "%ld", gid); + return NULL; + } else { + return strcpy(group, mygroup->gr_name); + } } diff --git a/libbb/my_getpwuid.c b/libbb/my_getpwuid.c index 2abe7a7..dfe9b49 100644 --- a/libbb/my_getpwuid.c +++ b/libbb/my_getpwuid.c @@ -28,15 +28,17 @@ /* gets a username given a uid */ -void my_getpwuid(char *name, long uid) +char * my_getpwuid(char *name, long uid) { struct passwd *myuser; myuser = getpwuid(uid); - if (myuser==NULL) - sprintf(name, "%-8ld ", (long)uid); - else - strcpy(name, myuser->pw_name); + if (myuser==NULL) { + sprintf(name, "%ld", (long)uid); + return NULL; + } else { + return strcpy(name, myuser->pw_name); + } } /* END CODE */ diff --git a/procps/ps.c b/procps/ps.c index aa40860..6036ffc 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -150,8 +150,6 @@ extern int ps_main(int argc, char **argv) /* Make some adjustments as needed */ my_getpwuid(uidName, p.ruid); - if (*uidName == '\0') - sprintf(uidName, "%d", p.ruid); sprintf(path, "/proc/%s/cmdline", entry->d_name); file = fopen(path, "r"); @@ -243,8 +241,6 @@ extern int ps_main(int argc, char **argv) /* Make some adjustments as needed */ my_getpwuid(uidName, info.euid); - if (*uidName == '\0') - sprintf(uidName, "%ld", info.euid); if(p.vmsize == 0) len = printf("%5d %-8s %c ", p.pid, uidName, p.state); diff --git a/sysklogd/logger.c b/sysklogd/logger.c index 380bde5..4aa1510 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c @@ -121,7 +121,7 @@ extern int logger_main(int argc, char **argv) pri = pencode(optarg); break; case 't': - strncpy(name, optarg, sizeof(name)); + safe_strncpy(name, optarg, sizeof(name)); break; default: show_usage(); @@ -144,7 +144,7 @@ extern int logger_main(int argc, char **argv) } while (c != EOF); } else { len = 1; /* for the '\0' */ - message=xcalloc(1, 1); + message = xcalloc(1, 1); for (i = optind; i < argc; i++) { len += strlen(argv[i]); len += 1; /* for the space between the args */ @@ -152,7 +152,7 @@ extern int logger_main(int argc, char **argv) strcat(message, argv[i]); strcat(message, " "); } - message[strlen(message)-1] = '\0'; + message[strlen(message) - 2] = '\0'; syslog(pri, "%s", message); } |