Only call fwrite() and fclose() when fp is not NULL

Spotted by Hiltjo.
This commit is contained in:
sin 2014-07-02 12:03:01 +01:00
parent 3669fa4117
commit c9609ea5ff
1 changed files with 7 additions and 5 deletions

View File

@ -89,12 +89,14 @@ main(int argc, char *argv[])
usr.ut_tv.tv_sec = time(NULL);
fp = fopen(UTMP_PATH, "a");
if (!fp)
weprintf("fopen %s:", UTMP_PATH);
if (fp) {
if (fwrite(&usr, sizeof(usr), 1, fp) != 1)
if (ferror(fp))
weprintf("%s: write error:", UTMP_PATH);
fclose(fp);
} else {
weprintf("fopen %s:", UTMP_PATH);
}
return dologin(pw, pflag);
}