[LEDE-DEV] [PATCH] Fix skipping directories in uci_list_config_files

Michal 'vorner' Vaner michal.vaner at nic.cz
Tue Nov 22 07:50:24 PST 2016


Don't create a hole in the array of configs if there's a directory. Such
a hole would be mistaken for the end of the array.

Signed-off-by: Michal 'vorner' Vaner <michal.vaner at nic.cz>
---
 file.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/file.c b/file.c
index 81047a4..6fc46bb 100644
--- a/file.c
+++ b/file.c
@@ -829,7 +829,7 @@ static char **uci_list_config_files(struct uci_context *ctx)
 {
 	char **configs;
 	glob_t globbuf;
-	int size, i;
+	int size, i, j, skipped;
 	char *buf;
 	char *dir;
 
@@ -841,18 +841,22 @@ static char **uci_list_config_files(struct uci_context *ctx)
 	}
 
 	size = sizeof(char *) * (globbuf.gl_pathc + 1);
+	skipped = 0;
 	for(i = 0; i < globbuf.gl_pathc; i++) {
 		char *p;
 
 		p = get_filename(globbuf.gl_pathv[i]);
-		if (!p)
+		if (!p) {
+			skipped++;
 			continue;
+		}
 
 		size += strlen(p) + 1;
 	}
 
-	configs = uci_malloc(ctx, size);
-	buf = (char *) &configs[globbuf.gl_pathc + 1];
+	configs = uci_malloc(ctx, size - skipped);
+	buf = (char *) &configs[globbuf.gl_pathc + 1 - skipped];
+	j = 0;
 	for(i = 0; i < globbuf.gl_pathc; i++) {
 		char *p;
 
@@ -863,7 +867,7 @@ static char **uci_list_config_files(struct uci_context *ctx)
 		if (!uci_validate_package(p))
 			continue;
 
-		configs[i] = buf;
+		configs[j++] = buf;
 		strcpy(buf, p);
 		buf += strlen(buf) + 1;
 	}
-- 
2.11.0.rc2




More information about the Lede-dev mailing list