aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-12-13 01:52:39 +0000
committerEric Andersen <andersen@codepoet.org>2000-12-13 01:52:39 +0000
commitbd193a42a5624f0a72b5f99d554e9a8d2afc64cc (patch)
tree7aacebe98730fbfee623943425a100fd158ba48a
parent77508b29fa63d99136fc09f00c5a2addd6331b4c (diff)
downloadbusybox-w32-bd193a42a5624f0a72b5f99d554e9a8d2afc64cc.tar.gz
busybox-w32-bd193a42a5624f0a72b5f99d554e9a8d2afc64cc.tar.bz2
busybox-w32-bd193a42a5624f0a72b5f99d554e9a8d2afc64cc.zip
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...
-rw-r--r--archival/tar.c2
-rw-r--r--coreutils/id.c12
-rw-r--r--coreutils/logname.c4
-rw-r--r--coreutils/ls.c2
-rw-r--r--coreutils/whoami.c4
-rw-r--r--id.c12
-rw-r--r--logname.c4
-rw-r--r--ls.c2
-rw-r--r--procps/ps.c13
-rw-r--r--ps.c13
-rw-r--r--tar.c2
-rw-r--r--utility.c2
-rw-r--r--whoami.c4
13 files changed, 26 insertions, 50 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 8c2650e2b..3a3b7f143 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -691,13 +691,11 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag,
691 struct tm *tm = localtime (&(header.mtime)); 691 struct tm *tm = localtime (&(header.mtime));
692 692
693 len=printf("%s ", mode_string(header.mode)); 693 len=printf("%s ", mode_string(header.mode));
694 memset(buf, 0, 8*sizeof(char));
695 my_getpwuid(buf, header.uid); 694 my_getpwuid(buf, header.uid);
696 if (! *buf) 695 if (! *buf)
697 len+=printf("%d", header.uid); 696 len+=printf("%d", header.uid);
698 else 697 else
699 len+=printf("%s", buf); 698 len+=printf("%s", buf);
700 memset(buf, 0, 8*sizeof(char));
701 my_getgrgid(buf, header.gid); 699 my_getgrgid(buf, header.gid);
702 if (! *buf) 700 if (! *buf)
703 len+=printf("/%-d ", header.gid); 701 len+=printf("/%-d ", header.gid);
diff --git a/coreutils/id.c b/coreutils/id.c
index 86667f516..3a8e77a1f 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -31,12 +31,11 @@
31extern int id_main(int argc, char **argv) 31extern int id_main(int argc, char **argv)
32{ 32{
33 int no_user = 0, no_group = 0, print_real = 0; 33 int no_user = 0, no_group = 0, print_real = 0;
34 char *cp, *user, *group; 34 char user[9], group[9];
35 long gid; 35 long gid;
36 long pwnam, grnam; 36 long pwnam, grnam;
37 int opt; 37 int opt;
38 38
39 cp = user = group = NULL;
40 gid = 0; 39 gid = 0;
41 40
42 while ((opt = getopt(argc, argv, "ugr")) > 0) { 41 while ((opt = getopt(argc, argv, "ugr")) > 0) {
@@ -57,11 +56,7 @@ extern int id_main(int argc, char **argv)
57 56
58 if (no_user && no_group) usage(id_usage); 57 if (no_user && no_group) usage(id_usage);
59 58
60 user = argv[optind]; 59 if (argv[optind] == NULL) {
61
62 if (user == NULL) {
63 user = xcalloc(9, sizeof(char));
64 group = xcalloc(9, sizeof(char));
65 if (print_real) { 60 if (print_real) {
66 my_getpwuid(user, getuid()); 61 my_getpwuid(user, getuid());
67 my_getgrgid(group, getgid()); 62 my_getgrgid(group, getgid());
@@ -70,7 +65,8 @@ extern int id_main(int argc, char **argv)
70 my_getgrgid(group, getegid()); 65 my_getgrgid(group, getegid());
71 } 66 }
72 } else { 67 } else {
73 group = xcalloc(9, sizeof(char)); 68 strncpy(user, argv[optind], 8);
69 user[8] = '\0';
74 gid = my_getpwnamegid(user); 70 gid = my_getpwnamegid(user);
75 my_getgrgid(group, gid); 71 my_getgrgid(group, gid);
76 } 72 }
diff --git a/coreutils/logname.c b/coreutils/logname.c
index 1fc518bfc..d614e85f1 100644
--- a/coreutils/logname.c
+++ b/coreutils/logname.c
@@ -25,13 +25,13 @@
25 25
26extern int logname_main(int argc, char **argv) 26extern int logname_main(int argc, char **argv)
27{ 27{
28 char *user = xmalloc(9); 28 char user[9];
29 29
30 if (argc > 1) 30 if (argc > 1)
31 usage(logname_usage); 31 usage(logname_usage);
32 32
33 my_getpwuid(user, geteuid()); 33 my_getpwuid(user, geteuid());
34 if (user) { 34 if (*user) {
35 puts(user); 35 puts(user);
36 return EXIT_SUCCESS; 36 return EXIT_SUCCESS;
37 } 37 }
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 94c73b377..655dd7ff4 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -600,13 +600,11 @@ int list_single(struct dnode *dn)
600 break; 600 break;
601 case LIST_ID_NAME: 601 case LIST_ID_NAME:
602#ifdef BB_FEATURE_LS_USERNAME 602#ifdef BB_FEATURE_LS_USERNAME
603 memset(scratch, 0, sizeof(scratch));
604 my_getpwuid(scratch, dn->dstat.st_uid); 603 my_getpwuid(scratch, dn->dstat.st_uid);
605 if (*scratch) 604 if (*scratch)
606 fprintf(stdout, "%-8.8s ", scratch); 605 fprintf(stdout, "%-8.8s ", scratch);
607 else 606 else
608 fprintf(stdout, "%-8d ", dn->dstat.st_uid); 607 fprintf(stdout, "%-8d ", dn->dstat.st_uid);
609 memset(scratch, 0, sizeof(scratch));
610 my_getgrgid(scratch, dn->dstat.st_gid); 608 my_getgrgid(scratch, dn->dstat.st_gid);
611 if (*scratch) 609 if (*scratch)
612 fprintf(stdout, "%-8.8s", scratch); 610 fprintf(stdout, "%-8.8s", scratch);
diff --git a/coreutils/whoami.c b/coreutils/whoami.c
index 6a5dd2c04..38a2b3078 100644
--- a/coreutils/whoami.c
+++ b/coreutils/whoami.c
@@ -26,14 +26,14 @@
26 26
27extern int whoami_main(int argc, char **argv) 27extern int whoami_main(int argc, char **argv)
28{ 28{
29 char *user = xmalloc(9); 29 char user[9];
30 uid_t uid = geteuid(); 30 uid_t uid = geteuid();
31 31
32 if (argc > 1) 32 if (argc > 1)
33 usage(whoami_usage); 33 usage(whoami_usage);
34 34
35 my_getpwuid(user, uid); 35 my_getpwuid(user, uid);
36 if (user) { 36 if (*user) {
37 puts(user); 37 puts(user);
38 return EXIT_SUCCESS; 38 return EXIT_SUCCESS;
39 } 39 }
diff --git a/id.c b/id.c
index 86667f516..3a8e77a1f 100644
--- a/id.c
+++ b/id.c
@@ -31,12 +31,11 @@
31extern int id_main(int argc, char **argv) 31extern int id_main(int argc, char **argv)
32{ 32{
33 int no_user = 0, no_group = 0, print_real = 0; 33 int no_user = 0, no_group = 0, print_real = 0;
34 char *cp, *user, *group; 34 char user[9], group[9];
35 long gid; 35 long gid;
36 long pwnam, grnam; 36 long pwnam, grnam;
37 int opt; 37 int opt;
38 38
39 cp = user = group = NULL;
40 gid = 0; 39 gid = 0;
41 40
42 while ((opt = getopt(argc, argv, "ugr")) > 0) { 41 while ((opt = getopt(argc, argv, "ugr")) > 0) {
@@ -57,11 +56,7 @@ extern int id_main(int argc, char **argv)
57 56
58 if (no_user && no_group) usage(id_usage); 57 if (no_user && no_group) usage(id_usage);
59 58
60 user = argv[optind]; 59 if (argv[optind] == NULL) {
61
62 if (user == NULL) {
63 user = xcalloc(9, sizeof(char));
64 group = xcalloc(9, sizeof(char));
65 if (print_real) { 60 if (print_real) {
66 my_getpwuid(user, getuid()); 61 my_getpwuid(user, getuid());
67 my_getgrgid(group, getgid()); 62 my_getgrgid(group, getgid());
@@ -70,7 +65,8 @@ extern int id_main(int argc, char **argv)
70 my_getgrgid(group, getegid()); 65 my_getgrgid(group, getegid());
71 } 66 }
72 } else { 67 } else {
73 group = xcalloc(9, sizeof(char)); 68 strncpy(user, argv[optind], 8);
69 user[8] = '\0';
74 gid = my_getpwnamegid(user); 70 gid = my_getpwnamegid(user);
75 my_getgrgid(group, gid); 71 my_getgrgid(group, gid);
76 } 72 }
diff --git a/logname.c b/logname.c
index 1fc518bfc..d614e85f1 100644
--- a/logname.c
+++ b/logname.c
@@ -25,13 +25,13 @@
25 25
26extern int logname_main(int argc, char **argv) 26extern int logname_main(int argc, char **argv)
27{ 27{
28 char *user = xmalloc(9); 28 char user[9];
29 29
30 if (argc > 1) 30 if (argc > 1)
31 usage(logname_usage); 31 usage(logname_usage);
32 32
33 my_getpwuid(user, geteuid()); 33 my_getpwuid(user, geteuid());
34 if (user) { 34 if (*user) {
35 puts(user); 35 puts(user);
36 return EXIT_SUCCESS; 36 return EXIT_SUCCESS;
37 } 37 }
diff --git a/ls.c b/ls.c
index 94c73b377..655dd7ff4 100644
--- a/ls.c
+++ b/ls.c
@@ -600,13 +600,11 @@ int list_single(struct dnode *dn)
600 break; 600 break;
601 case LIST_ID_NAME: 601 case LIST_ID_NAME:
602#ifdef BB_FEATURE_LS_USERNAME 602#ifdef BB_FEATURE_LS_USERNAME
603 memset(scratch, 0, sizeof(scratch));
604 my_getpwuid(scratch, dn->dstat.st_uid); 603 my_getpwuid(scratch, dn->dstat.st_uid);
605 if (*scratch) 604 if (*scratch)
606 fprintf(stdout, "%-8.8s ", scratch); 605 fprintf(stdout, "%-8.8s ", scratch);
607 else 606 else
608 fprintf(stdout, "%-8d ", dn->dstat.st_uid); 607 fprintf(stdout, "%-8d ", dn->dstat.st_uid);
609 memset(scratch, 0, sizeof(scratch));
610 my_getgrgid(scratch, dn->dstat.st_gid); 608 my_getgrgid(scratch, dn->dstat.st_gid);
611 if (*scratch) 609 if (*scratch)
612 fprintf(stdout, "%-8.8s", scratch); 610 fprintf(stdout, "%-8.8s", scratch);
diff --git a/procps/ps.c b/procps/ps.c
index 79910fe34..357ece383 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -121,8 +121,8 @@ extern int ps_main(int argc, char **argv)
121 FILE *file; 121 FILE *file;
122 struct dirent *entry; 122 struct dirent *entry;
123 char path[32], sbuf[512]; 123 char path[32], sbuf[512];
124 char uidName[10] = ""; 124 char uidName[9];
125 char groupName[10] = ""; 125 char groupName[9];
126 int len, i, c; 126 int len, i, c;
127#ifdef BB_FEATURE_AUTOWIDTH 127#ifdef BB_FEATURE_AUTOWIDTH
128 struct winsize win = { 0, 0, 0, 0 }; 128 struct winsize win = { 0, 0, 0, 0 };
@@ -146,9 +146,6 @@ extern int ps_main(int argc, char **argv)
146 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", 146 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
147 "State", "Command"); 147 "State", "Command");
148 while ((entry = readdir(dir)) != NULL) { 148 while ((entry = readdir(dir)) != NULL) {
149 uidName[0] = '\0';
150 groupName[0] = '\0';
151
152 if (!isdigit(*entry->d_name)) 149 if (!isdigit(*entry->d_name))
153 continue; 150 continue;
154 sprintf(path, "/proc/%s/status", entry->d_name); 151 sprintf(path, "/proc/%s/status", entry->d_name);
@@ -204,8 +201,8 @@ extern int ps_main(int argc, char **argv)
204 pid_t num_pids; 201 pid_t num_pids;
205 pid_t* pid_array = NULL; 202 pid_t* pid_array = NULL;
206 struct pid_info info; 203 struct pid_info info;
207 char uidName[10] = ""; 204 char uidName[9];
208 char groupName[10] = ""; 205 char groupName[9];
209#ifdef BB_FEATURE_AUTOWIDTH 206#ifdef BB_FEATURE_AUTOWIDTH
210 struct winsize win = { 0, 0, 0, 0 }; 207 struct winsize win = { 0, 0, 0, 0 };
211 int terminal_width = TERMINAL_WIDTH; 208 int terminal_width = TERMINAL_WIDTH;
@@ -247,8 +244,6 @@ extern int ps_main(int argc, char **argv)
247 "State", "Command"); 244 "State", "Command");
248 245
249 for (i=1; i<pid_array[0] ; i++) { 246 for (i=1; i<pid_array[0] ; i++) {
250 uidName[0] = '\0';
251 groupName[0] = '\0';
252 info.pid = pid_array[i]; 247 info.pid = pid_array[i];
253 248
254 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) 249 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
diff --git a/ps.c b/ps.c
index 79910fe34..357ece383 100644
--- a/ps.c
+++ b/ps.c
@@ -121,8 +121,8 @@ extern int ps_main(int argc, char **argv)
121 FILE *file; 121 FILE *file;
122 struct dirent *entry; 122 struct dirent *entry;
123 char path[32], sbuf[512]; 123 char path[32], sbuf[512];
124 char uidName[10] = ""; 124 char uidName[9];
125 char groupName[10] = ""; 125 char groupName[9];
126 int len, i, c; 126 int len, i, c;
127#ifdef BB_FEATURE_AUTOWIDTH 127#ifdef BB_FEATURE_AUTOWIDTH
128 struct winsize win = { 0, 0, 0, 0 }; 128 struct winsize win = { 0, 0, 0, 0 };
@@ -146,9 +146,6 @@ extern int ps_main(int argc, char **argv)
146 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", 146 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
147 "State", "Command"); 147 "State", "Command");
148 while ((entry = readdir(dir)) != NULL) { 148 while ((entry = readdir(dir)) != NULL) {
149 uidName[0] = '\0';
150 groupName[0] = '\0';
151
152 if (!isdigit(*entry->d_name)) 149 if (!isdigit(*entry->d_name))
153 continue; 150 continue;
154 sprintf(path, "/proc/%s/status", entry->d_name); 151 sprintf(path, "/proc/%s/status", entry->d_name);
@@ -204,8 +201,8 @@ extern int ps_main(int argc, char **argv)
204 pid_t num_pids; 201 pid_t num_pids;
205 pid_t* pid_array = NULL; 202 pid_t* pid_array = NULL;
206 struct pid_info info; 203 struct pid_info info;
207 char uidName[10] = ""; 204 char uidName[9];
208 char groupName[10] = ""; 205 char groupName[9];
209#ifdef BB_FEATURE_AUTOWIDTH 206#ifdef BB_FEATURE_AUTOWIDTH
210 struct winsize win = { 0, 0, 0, 0 }; 207 struct winsize win = { 0, 0, 0, 0 };
211 int terminal_width = TERMINAL_WIDTH; 208 int terminal_width = TERMINAL_WIDTH;
@@ -247,8 +244,6 @@ extern int ps_main(int argc, char **argv)
247 "State", "Command"); 244 "State", "Command");
248 245
249 for (i=1; i<pid_array[0] ; i++) { 246 for (i=1; i<pid_array[0] ; i++) {
250 uidName[0] = '\0';
251 groupName[0] = '\0';
252 info.pid = pid_array[i]; 247 info.pid = pid_array[i];
253 248
254 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) 249 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
diff --git a/tar.c b/tar.c
index 8c2650e2b..3a3b7f143 100644
--- a/tar.c
+++ b/tar.c
@@ -691,13 +691,11 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag,
691 struct tm *tm = localtime (&(header.mtime)); 691 struct tm *tm = localtime (&(header.mtime));
692 692
693 len=printf("%s ", mode_string(header.mode)); 693 len=printf("%s ", mode_string(header.mode));
694 memset(buf, 0, 8*sizeof(char));
695 my_getpwuid(buf, header.uid); 694 my_getpwuid(buf, header.uid);
696 if (! *buf) 695 if (! *buf)
697 len+=printf("%d", header.uid); 696 len+=printf("%d", header.uid);
698 else 697 else
699 len+=printf("%s", buf); 698 len+=printf("%s", buf);
700 memset(buf, 0, 8*sizeof(char));
701 my_getgrgid(buf, header.gid); 699 my_getgrgid(buf, header.gid);
702 if (! *buf) 700 if (! *buf)
703 len+=printf("/%-d ", header.gid); 701 len+=printf("/%-d ", header.gid);
diff --git a/utility.c b/utility.c
index 0e170d1c1..61e5f7a73 100644
--- a/utility.c
+++ b/utility.c
@@ -957,12 +957,14 @@ long my_getgrnam(char *name)
957/* gets a username given a uid */ 957/* gets a username given a uid */
958void my_getpwuid(char *name, long uid) 958void my_getpwuid(char *name, long uid)
959{ 959{
960 name[0] = '\0';
960 my_getid("/etc/passwd", name, uid, NULL); 961 my_getid("/etc/passwd", name, uid, NULL);
961} 962}
962 963
963/* gets a groupname given a gid */ 964/* gets a groupname given a gid */
964void my_getgrgid(char *group, long gid) 965void my_getgrgid(char *group, long gid)
965{ 966{
967 group[0] = '\0';
966 my_getid("/etc/group", group, gid, NULL); 968 my_getid("/etc/group", group, gid, NULL);
967} 969}
968 970
diff --git a/whoami.c b/whoami.c
index 6a5dd2c04..38a2b3078 100644
--- a/whoami.c
+++ b/whoami.c
@@ -26,14 +26,14 @@
26 26
27extern int whoami_main(int argc, char **argv) 27extern int whoami_main(int argc, char **argv)
28{ 28{
29 char *user = xmalloc(9); 29 char user[9];
30 uid_t uid = geteuid(); 30 uid_t uid = geteuid();
31 31
32 if (argc > 1) 32 if (argc > 1)
33 usage(whoami_usage); 33 usage(whoami_usage);
34 34
35 my_getpwuid(user, uid); 35 my_getpwuid(user, uid);
36 if (user) { 36 if (*user) {
37 puts(user); 37 puts(user);
38 return EXIT_SUCCESS; 38 return EXIT_SUCCESS;
39 } 39 }