From 8335dd84ca85651115d518d7e3d963de9d82e22f Mon Sep 17 00:00:00 2001 From: Tomas Korbar Date: Wed, 16 Sep 2020 14:05:05 +0200 Subject: Improve opening of authentication file --- authfile.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'authfile.c') diff --git a/authfile.c b/authfile.c index f8935af..5f001d1 100644 --- a/authfile.c +++ b/authfile.c @@ -33,23 +33,16 @@ enum authfile_ret authfile_load(const char *file) { char *auth_data = NULL; auth_t auth_entries[MAX_ENTRIES]; - if (stat(file, &sb) == -1) { - return AUTHFILE_MISSING; - } - - auth_data = calloc(1, sb.st_size); - - if (auth_data == NULL) { - return AUTHFILE_OOM; - } - FILE *pwfile = fopen(file, "r"); if (pwfile == NULL) { - // not strictly necessary but to be safe. - free(auth_data); return AUTHFILE_OPENFAIL; + } else if (fstat(fileno(pwfile), &sb)) { + fclose(pwfile); + return AUTHFILE_STATFAIL; } + auth_data = calloc(1, sb.st_size); + char *auth_cur = auth_data; auth_t *entry_cur = auth_entries; int used = 0; -- cgit v1.2.1