fix bad memset in getpwent

This commit is contained in:
K. Lange 2018-02-28 16:22:58 +09:00 committed by Kevin Lange
parent b6bdcc979e
commit 06d5e61af6

View File

@ -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);
}