[hackers] [ubase] Only call fwrite() and fclose() when fp is not NULL || sin
commit c9609ea5ff66f226a2829ab4e00d2b2f8212e3b8
Author: sin <sin_AT_2f30.org>
Date: Wed Jul 2 12:03:01 2014 +0100
Only call fwrite() and fclose() when fp is not NULL
Spotted by Hiltjo.
diff --git a/login.c b/login.c
index ef6d501..aec561f 100644
--- a/login.c
+++ b/login.c
_AT_@ -89,12 +89,14 @@ main(int argc, char *argv[])
usr.ut_tv.tv_sec = time(NULL);
fp = fopen(UTMP_PATH, "a");
- if (!fp)
+ 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);
- if (fwrite(&usr, sizeof(usr), 1, fp) != 1)
- if (ferror(fp))
- weprintf("%s: write error:", UTMP_PATH);
- fclose(fp);
+ }
return dologin(pw, pflag);
}
Received on Wed Jul 02 2014 - 13:09:05 CEST
This archive was generated by hypermail 2.3.0
: Wed Jul 02 2014 - 13:12:17 CEST