[OpenWrt-Devel] [PATCH] uhttpd: Fix possible memory leaks when generating directory listing

Andrej Krpic ak77 at tnode.com
Mon Dec 22 13:05:29 EST 2014


scandir() call requires free() of each returned dirent structure
and parent list. Code constructing HTML response of directory
listing is missing a call to free in some cases.

Signed-off-by: Andrej Krpic <ak77 at tnode.com>
---
 file.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/file.c b/file.c
index 6b3bb82..60dfdfa 100644
--- a/file.c
+++ b/file.c
@@ -479,11 +479,11 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
 		bool dir = !!(files[i]->d_type & DT_DIR);
 
 		if (name[0] == '.' && name[1] == 0)
-			continue;
+			goto next;
 
 		sprintf(file, "%s", name);
 		if (stat(local_path, &s))
-			continue;
+			goto next;
 
 		if (!dir) {
 			suffix = "";
@@ -492,7 +492,7 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
 		}
 
 		if (!(s.st_mode & mode))
-			continue;
+			goto next;
 
 		uh_chunk_printf(cl,
 				"<li><strong><a href='%s%s%s'>%s</a>%s"
@@ -505,6 +505,7 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
 				type, s.st_size / 1024.0);
 
 		*file = 0;
+next:
 		free(files[i]);
 	}
 }
-- 
1.7.10.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list