diff options
author | Eric Andersen | 2000-12-13 01:52:39 +0000 |
---|---|---|
committer | Eric Andersen | 2000-12-13 01:52:39 +0000 |
commit | bd193a42a5624f0a72b5f99d554e9a8d2afc64cc (patch) | |
tree | 7aacebe98730fbfee623943425a100fd158ba48a /coreutils | |
parent | 77508b29fa63d99136fc09f00c5a2addd6331b4c (diff) | |
download | busybox-bd193a42a5624f0a72b5f99d554e9a8d2afc64cc.zip busybox-bd193a42a5624f0a72b5f99d554e9a8d2afc64cc.tar.gz |
Fix from Matt Kraai -- a better way to NULL terminate strings for the
my_* passwd and group routines. I should have thought of doing it
this way...
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/id.c | 12 | ||||
-rw-r--r-- | coreutils/logname.c | 4 | ||||
-rw-r--r-- | coreutils/ls.c | 2 | ||||
-rw-r--r-- | coreutils/whoami.c | 4 |
4 files changed, 8 insertions, 14 deletions
diff --git a/coreutils/id.c b/coreutils/id.c index 86667f5..3a8e77a 100644 --- a/coreutils/id.c +++ b/coreutils/id.c @@ -31,12 +31,11 @@ extern int id_main(int argc, char **argv) { int no_user = 0, no_group = 0, print_real = 0; - char *cp, *user, *group; + char user[9], group[9]; long gid; long pwnam, grnam; int opt; - cp = user = group = NULL; gid = 0; while ((opt = getopt(argc, argv, "ugr")) > 0) { @@ -57,11 +56,7 @@ extern int id_main(int argc, char **argv) if (no_user && no_group) usage(id_usage); - user = argv[optind]; - - if (user == NULL) { - user = xcalloc(9, sizeof(char)); - group = xcalloc(9, sizeof(char)); + if (argv[optind] == NULL) { if (print_real) { my_getpwuid(user, getuid()); my_getgrgid(group, getgid()); @@ -70,7 +65,8 @@ extern int id_main(int argc, char **argv) my_getgrgid(group, getegid()); } } else { - group = xcalloc(9, sizeof(char)); + strncpy(user, argv[optind], 8); + user[8] = '\0'; gid = my_getpwnamegid(user); my_getgrgid(group, gid); } diff --git a/coreutils/logname.c b/coreutils/logname.c index 1fc518b..d614e85 100644 --- a/coreutils/logname.c +++ b/coreutils/logname.c @@ -25,13 +25,13 @@ extern int logname_main(int argc, char **argv) { - char *user = xmalloc(9); + char user[9]; if (argc > 1) usage(logname_usage); my_getpwuid(user, geteuid()); - if (user) { + if (*user) { puts(user); return EXIT_SUCCESS; } diff --git a/coreutils/ls.c b/coreutils/ls.c index 94c73b3..655dd7f 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -600,13 +600,11 @@ int list_single(struct dnode *dn) break; case LIST_ID_NAME: #ifdef BB_FEATURE_LS_USERNAME - memset(scratch, 0, sizeof(scratch)); my_getpwuid(scratch, dn->dstat.st_uid); if (*scratch) fprintf(stdout, "%-8.8s ", scratch); else fprintf(stdout, "%-8d ", dn->dstat.st_uid); - memset(scratch, 0, sizeof(scratch)); my_getgrgid(scratch, dn->dstat.st_gid); if (*scratch) fprintf(stdout, "%-8.8s", scratch); diff --git a/coreutils/whoami.c b/coreutils/whoami.c index 6a5dd2c..38a2b30 100644 --- a/coreutils/whoami.c +++ b/coreutils/whoami.c @@ -26,14 +26,14 @@ extern int whoami_main(int argc, char **argv) { - char *user = xmalloc(9); + char user[9]; uid_t uid = geteuid(); if (argc > 1) usage(whoami_usage); my_getpwuid(user, uid); - if (user) { + if (*user) { puts(user); return EXIT_SUCCESS; } |