Config file include order bug?
Sven Hartge
sven at svenhartge.de
Wed Jul 15 17:54:58 CEST 2020
Um 17:49 Uhr am 15.07.20 schrieb Sven Hartge:
> On 15.07.20 17:14, Alan DeKok wrote:
>> On Jul 15, 2020, at 8:19 AM, Sven Hartge <sven at svenhartge.de> wrote:
>>> And in the end the load order should be fixed by sorting before loading to make it stable for everyone and not break semi-randomly based on the way a filesystem presents/stores the entries in a directory.
>
>> As alway, patches are welcome.
>
> OK, please see the attached diff.
Right, the list strips attachments. So here it is inline:
diff --git a/src/main/conffile.c b/src/main/conffile.c
index a8c667bfb5..a4494ef7ad 100644
--- a/src/main/conffile.c
+++ b/src/main/conffile.c
@@ -2476,8 +2476,9 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp,
* careful!
*/
if (value[strlen(value) - 1] == '/') {
- DIR *dir;
struct dirent *dp;
+ struct dirent **namelist;
+ int n,i;
struct stat stat_buf;
DEBUG2("including files in directory %s", value );
@@ -2498,8 +2499,8 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp,
return -1;
}
#endif
- dir = opendir(value);
- if (!dir) {
+ n = scandir(value, &namelist, NULL, alphasort);
+ if (n == -1) {
ERROR("%s[%d]: Error reading directory %s: %s",
filename, *lineno, value,
fr_syserror(errno));
@@ -2509,9 +2510,12 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp,
/*
* Read the directory, ignoring "." files.
*/
- while ((dp = readdir(dir)) != NULL) {
+ for (i=0; i<n; i++) {
char const *p;
+ dp = namelist[i];
+ free(namelist[i]);
+
if (dp->d_name[0] == '.') continue;
/*
@@ -2537,11 +2541,11 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp,
* configuration section.
*/
if (cf_file_include(this, buf2, true) < 0) {
- closedir(dir);
+ free(namelist);
return -1;
}
}
- closedir(dir);
+ free(namelist);
} else
#endif
{ /* it was a normal file */
More information about the Freeradius-Users
mailing list