From patchwork Mon Dec 22 18:05:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Krpic X-Patchwork-Id: 423477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C18291400B7 for ; Tue, 23 Dec 2014 05:20:20 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 17A8328BD30; Mon, 22 Dec 2014 19:18:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 614AF28A62A for ; Mon, 22 Dec 2014 19:18:13 +0100 (CET) X-policyd-weight: using cached result; rate: -7.6 Received: from mail.tnode.com (mail.tnode.com [46.54.226.45]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 22 Dec 2014 19:18:13 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.tnode.com (Postfix) with ESMTP id 2985A43C00BB; Mon, 22 Dec 2014 19:20:08 +0100 (CET) Received: from mail.tnode.com ([127.0.0.1]) by localhost (mail.tnode.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5qruGEQsF-dz; Mon, 22 Dec 2014 19:20:04 +0100 (CET) From: Andrej Krpic To: openwrt-devel@lists.openwrt.org Date: Mon, 22 Dec 2014 19:05:29 +0100 Message-Id: <1419271529-29987-1-git-send-email-ak77@tnode.com> X-Mailer: git-send-email 1.7.10.4 Subject: [OpenWrt-Devel] [PATCH] uhttpd: Fix possible memory leaks when generating directory listing X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 --- 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, "
  • %s%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]); } }