summaryrefslogtreecommitdiff
path: root/authfile.c
diff options
context:
space:
mode:
authorTomas Korbar <tkorbar@redhat.com>2020-09-16 14:05:05 +0200
committerdormando <dormando@rydia.net>2020-10-26 16:43:03 -0700
commit8335dd84ca85651115d518d7e3d963de9d82e22f (patch)
tree3664bbce88218691322b6e828bbf37a42a8b1eb9 /authfile.c
parentb031143f8ab61296ddbf6c4470c5dcdbf7ae588b (diff)
downloadmemcached-8335dd84ca85651115d518d7e3d963de9d82e22f.tar.gz
Improve opening of authentication file1.6.8
Diffstat (limited to 'authfile.c')
-rw-r--r--authfile.c17
1 files changed, 5 insertions, 12 deletions
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;