From patchwork Wed Nov 23 11:31:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Ilin X-Patchwork-Id: 1708269 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=N5YjmvWQ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NHJqL2j6Nz23mf for ; Wed, 23 Nov 2022 22:31:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1A52484E79; Wed, 23 Nov 2022 12:31:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="N5YjmvWQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EF42F84F03; Wed, 23 Nov 2022 12:31:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C21B284E3A for ; Wed, 23 Nov 2022 12:31:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilin.mikhail.ol@gmail.com Received: by mail-lf1-x12b.google.com with SMTP id p8so27695611lfu.11 for ; Wed, 23 Nov 2022 03:31:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wypEUyz7P2h7FzISlPXZFQ/1xVCd2GCTPPFb3t+r2XE=; b=N5YjmvWQl5y8VxH6wXHlZrwCw+Ik3mBq7xFeLBrRrZRqhzEcy7gykNdjECS5h1B4Lv 6N1tpRWGr2lLpcn1iZVF9rdQjm+pbUJJfNuJHd3A5IEqgxgiodoAUnAAaun36qJ4Qe98 By9rLIWKaGx7mHDTpbghTjdTzby9FL2TQdHo6PC0uVeyEet62/PINDXzie9O/GjjJk4O aHl5QGcRjEbM7tVgNtCTAq9Rt7cmvG0hnRfXdidE/+LRTRl+M9cUyY6p0UYgb+as8K9c Yy/sQkKL3rvpT3ip4101WKoMRHGuhtG8gLYmPccR37qXVN+I6Vtc+QwxIBduR92cUkBe iIhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wypEUyz7P2h7FzISlPXZFQ/1xVCd2GCTPPFb3t+r2XE=; b=Y7KQdUCTWssAggriLfxwjLzBjkVqpMSGR+OHPe7gXogqzbf4iEsFpEH8HXll88PdNg I9k+4a+WMJ4uwtPt4gtZPxIN2K30woeIBm7uiG6rCZ3cL8sPK9jLnq/8C1SYaDyysSYi pOSeI+NSsPOx70XDnsLXKk5WscFxVPiliPJeCevBZ9eKC20KtjkgHboD4ybQUDqN3975 CF9797N8I/a8AUL5LV+eHTO2p4+Q5pvYA9Bv02W0i6JWOqG+5G37uVAonxFbJf31luCK CbcKLMuRxrhkPxtExJcWEczLhjGdU8HCcW1L4OfOEs2fvDrrCp5RScASdI5WKiNg0K4S Dcfw== X-Gm-Message-State: ANoB5pk1/ich8D2pW9CXNB+bH0oX+/k9NlLmsnbvred96CY/O3wr3a22 fNvxiq9um10IGHXOHjlko9g= X-Google-Smtp-Source: AA0mqf4K4eQdNQiS903EfDQNC4ldIpA7nt7KnjgS0+jY/VpuKxnmuVKjVELa8eqSvzfozj1fCc4LFQ== X-Received: by 2002:a05:6512:b8c:b0:4a2:39e6:4d48 with SMTP id b12-20020a0565120b8c00b004a239e64d48mr9446421lfv.234.1669203071123; Wed, 23 Nov 2022 03:31:11 -0800 (PST) Received: from milin-wrk.rasu.local ([178.70.40.200]) by smtp.gmail.com with ESMTPSA id f17-20020a0565123b1100b00499f9aaa9desm2858355lfv.179.2022.11.23.03.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 03:31:10 -0800 (PST) From: Mikhail Ilin To: Simon Glass Cc: Mikhail Ilin , u-boot@lists.denx.de Subject: [PATCH] tools: fdtgrep: Fix handle leak Date: Wed, 23 Nov 2022 14:31:03 +0300 Message-Id: <20221123113103.28671-1-ilin.mikhail.ol@gmail.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The handle "fd" was created in fdtgrep.c:708 by calling the "open" function and is lost in fdtgrep.c:716 and fdtgrep.c:723. Close file descriptor 'fd' before exiting with an error from function utilfdt_read_err_len(const char *filename, char **buffp, off_t *len). Fixes: 1043d0a0296a ("fdt: Add fdtgrep tool") Signed-off-by: Mikhail Ilin Reviewed-by: Simon Glass --- tools/fdtgrep.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 641d6a2e3e..7eabcab439 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -712,15 +712,19 @@ int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len) /* Loop until we have read everything */ buf = malloc(bufsize); - if (!buf) + if (!buf) { + close(fd); return -ENOMEM; + } do { /* Expand the buffer to hold the next chunk */ if (offset == bufsize) { bufsize *= 2; buf = realloc(buf, bufsize); - if (!buf) + if (!buf) { + close(fd); return -ENOMEM; + } } ret = read(fd, &buf[offset], bufsize - offset);