fix bad memset in getpwent
This commit is contained in:
parent
b6bdcc979e
commit
06d5e61af6
10
libc/pwd.c
10
libc/pwd.c
@ -40,14 +40,18 @@ static struct passwd * pw_ent;
|
||||
static char * pw_blob;
|
||||
|
||||
struct passwd * fgetpwent(FILE * stream) {
|
||||
if (!stream) {
|
||||
return NULL;
|
||||
}
|
||||
if (!pw_ent) {
|
||||
pw_ent = malloc(sizeof(struct passwd));
|
||||
pw_blob = malloc(LINE_LEN);
|
||||
}
|
||||
|
||||
memset(pw_blob, 0x00, sizeof(pw_blob));
|
||||
memset(pw_blob, 0x00, LINE_LEN);
|
||||
fgets(pw_blob, LINE_LEN, stream);
|
||||
|
||||
|
||||
if (pw_blob[strlen(pw_blob)-1] == '\n') {
|
||||
pw_blob[strlen(pw_blob)-1] = '\0'; /* erase newline */
|
||||
}
|
||||
@ -79,6 +83,10 @@ struct passwd * getpwent(void) {
|
||||
open_it();
|
||||
}
|
||||
|
||||
if (!pwdb) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fgetpwent(pwdb);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user