From patchwork Mon Jan 31 22:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Berger X-Patchwork-Id: 538485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8314CC433EF for ; Mon, 31 Jan 2022 22:31:28 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5DC091688; Mon, 31 Jan 2022 23:30:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5DC091688 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1643668286; bh=Jzqhd0mrCTwJXhLqgFYZuTVuQ9pLYFyipZDkQnbM97Q=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=vm/w7OA9fUqd8KX5uaEh3jUTtkNBqm0DXh+TH3pQ3Osk83vH+D+7mGWrORmaE10rV 3jx2x4vwWGgEmZldscOza6XMWalMKkvYjKWuuF+6Myir+lZWAOiwdWw/aFO8me9kiE me+3hYwRA9pmaF9lezYaZLr0hkk9mZV885Kicvio= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E4AE1F8016C; Mon, 31 Jan 2022 23:30:35 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7516BF8028B; Mon, 31 Jan 2022 23:30:34 +0100 (CET) Received: from mout-y-111.mailbox.org (mout-y-111.mailbox.org [91.198.250.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id CB9DFF80095 for ; Mon, 31 Jan 2022 23:30:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CB9DFF80095 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="xo8H44BG" Received: from smtp202.mailbox.org (unknown [91.198.250.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-111.mailbox.org (Postfix) with ESMTPS id 4JnjSG6XzZz9sRJ; Mon, 31 Jan 2022 23:30:22 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1643668222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FSgwgUdLocijzgTLpqFeo9oLYF96EeX1MIVS0VYYoRw=; b=xo8H44BGjAcav34XfpSKoaAjkNULdguOxgvIdSrFyVPtQT+fkUREQ5VH7AtyRBAWP2g/u8 P/SZhTiq+yV9ytE99IldOZNUWTKPCG1XtsHpQxjCqqGjrUu/hiNjNU9hRHIFJuEGJuWM/1 FZ4j+Q4FfMTeyzAf6dAQQnq2rCXeyTWB59GeZXyF+4nrq2+FeRbU/yhSH/s5bexFYsF1OT 4TwVspmk2IOM7TBQ5ElocOxZuXSj1cny0Fgo/zkJQ31li2eTtn+2G8a8F7R6SqBQCHwtLy utPZyCB5IiggCMNzbEtVDejoiiryRGEP3IrD1KSBYPYhJbxsUsY8WgBIXbbQmQ== From: Sebastian Berger To: alsa-devel@alsa-project.org Subject: [PATCH] conf: fix memory leaks in parse_def() Date: Mon, 31 Jan 2022 23:29:07 +0100 Message-Id: <20220131222906.82279-1-sebastian.berger@mailbox.org> MIME-Version: 1.0 Cc: Sebastian Berger X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For all execution paths in parse_def(), free the id string before returning. Previous implementations fail to do this if the configuration: (1) tries to reference the child of a non-compound node, or (2) does not provide a valid argument after an assignment ('=') operator. For example, the invocations: (1) snd_config_load_string(&conf, "foo 0 foo.a 1", 0) (2) snd_config_load_string(&conf, "bar =", 0) would leak the strings "foo" or "bar", respectively. Signed-off-by: Sebastian Berger --- src/conf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 70f0e773..8a09505b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1403,7 +1403,8 @@ static int parse_def(snd_config_t *parent, input_t *input, int skip, int overrid if (mode != OVERRIDE) { if (n->type != SND_CONFIG_TYPE_COMPOUND) { SNDERR("%s is not a compound", id); - return -EINVAL; + err = -EINVAL; + goto __end; } n->u.compound.join = true; parent = n; @@ -1425,8 +1426,10 @@ static int parse_def(snd_config_t *parent, input_t *input, int skip, int overrid } if (c == '=') { c = get_nonwhite(input); - if (c < 0) - return c; + if (c < 0) { + err = c; + goto __end; + } } if (!skip) { if (_snd_config_search(parent, id, -1, &n) == 0) {