From: Alan T. DeKok Date: Thu, 25 Jun 2015 15:28:37 +0000 (-0400) Subject: Revert "Unecessary fileno(), just do as cf_file_input()" X-Git-Tag: release_3_0_9~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f817df1f0c12fabe8206eabffb1803fe2dc7d0d2;p=thirdparty%2Ffreeradius-server.git Revert "Unecessary fileno(), just do as cf_file_input()" This reverts commit 44fc841929934a55f690422ee1d25c3190c5c900. stat() is not the same as fstat(). The first one checks a file which has the same name as the one we opened. The second checks the file which we just opened. The cf_file_input() checks just check if the filename for security (globally writeable, etc.). cf_file_open() will open the file and read it's contents --- diff --git a/src/main/conffile.c b/src/main/conffile.c index 235c456f878..95d6bddc19b 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -305,6 +305,7 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename) CONF_DATA *cd; CONF_SECTION *top; rbtree_t *tree; + int fd; FILE *fp; top = cf_top_section(cs); @@ -320,6 +321,8 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename) return NULL; } + fd = fileno(fp); + file = talloc(tree, cf_file_t); if (!file) { fclose(fp); @@ -330,7 +333,7 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename) file->cs = cs; file->input = true; - if (stat(filename, &file->buf) < 0) { + if (fstat(fd, &file->buf) == 0) { #ifdef S_IWOTH if ((file->buf.st_mode & S_IWOTH) != 0) { ERROR("Configuration file %s is globally writable. " @@ -372,6 +375,7 @@ static bool cf_file_input(CONF_SECTION *cs, char const *filename) if (!cd) return false; tree = cd->data; + file = talloc(tree, cf_file_t); if (!file) return false;