TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */
- if (my_getpwuid(header.uname, statbuf->st_uid) == NULL)
+ if (my_getpwuid(header.uname, statbuf->st_uid, sizeof(header.uname)) == NULL)
strcpy(header.uname, "root");
- if (my_getgrgid(header.gname, statbuf->st_gid) == NULL)
+ if (my_getgrgid(header.gname, statbuf->st_gid, sizeof(header.gname)) == NULL)
strcpy(header.gname, "root");
if (tbInfo->hlInfo) {
extern int id_main(int argc, char **argv)
{
- char user[9], group[9];
+ char user[32], group[32];
long pwnam, grnam;
int uid, gid;
int flags;
uid = geteuid();
gid = getegid();
}
- my_getpwuid(user, uid);
+ my_getpwuid(user, uid, sizeof(user));
} else {
safe_strncpy(user, argv[optind], sizeof(user));
gid = my_getpwnamegid(user);
}
- my_getgrgid(group, gid);
+ my_getgrgid(group, gid, sizeof(group));
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
break;
case LIST_ID_NAME:
#ifdef CONFIG_FEATURE_LS_USERNAME
- my_getpwuid(scratch, dn->dstat.st_uid);
+ my_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
printf("%-8.8s ", scratch);
- my_getgrgid(scratch, dn->dstat.st_gid);
+ my_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
printf("%-8.8s", scratch);
column += 17;
break;
bb_show_usage();
uid = geteuid();
- if (my_getpwuid(user, uid)) {
+ if (my_getpwuid(user, uid, sizeof(user))) {
puts(user);
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
* 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 char * my_getpwuid(char *name, long uid);
-extern char * my_getgrgid(char *group, long gid);
+extern char * my_getpwuid(char *name, long uid, int bufsize);
+extern char * my_getgrgid(char *group, long gid, int bufsize);
extern long my_getpwnamegid(const char *name);
extern char *bb_askpass(int timeout, const char * prompt);
/* gets a groupname given a gid */
-char * my_getgrgid(char *group, long gid)
+char * my_getgrgid(char *group, long gid, int bufsize)
{
struct group *mygroup;
mygroup = getgrgid(gid);
if (mygroup==NULL) {
- sprintf(group, "%ld", gid);
+ snprintf(group, bufsize, "%ld", gid);
return NULL;
} else {
- return strcpy(group, mygroup->gr_name);
+ return safe_strncpy(group, mygroup->gr_name, bufsize);
}
}
/* gets a username given a uid */
-char * my_getpwuid(char *name, long uid)
+char * my_getpwuid(char *name, long uid, int bufsize)
{
struct passwd *myuser;
myuser = getpwuid(uid);
if (myuser==NULL) {
- sprintf(name, "%ld", (long)uid);
+ snprintf(name, bufsize, "%ld", (long)uid);
return NULL;
} else {
- return strcpy(name, myuser->pw_name);
+ return safe_strncpy(name, myuser->pw_name, bufsize);
}
}
sprintf(status, "/proc/%d", pid);
if(stat(status, &sb))
continue;
- my_getpwuid(curstatus.user, sb.st_uid);
+ my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
sprintf(status, "/proc/%d/stat", pid);
if((fp = fopen(status, "r")) == NULL)
char buf[1024], name[128];
/* Fill out the name string early (may be overwritten later) */
- my_getpwuid(name, geteuid());
+ my_getpwuid(name, geteuid(), sizeof(name));
/* Parse any options */
while ((opt = getopt(argc, argv, "p:st:")) > 0) {