From patchwork Wed May 12 11:24:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1477555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=V65Dpb0x; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FgC9q4nHVz9sWQ for ; Wed, 12 May 2021 21:24:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DB3D3835426; Wed, 12 May 2021 11:24:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DB3D3835426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620818669; bh=rJ9ZDS6KCHaeUwKxVoqtz2/QfFoMbR2Cd6I78JXpJyk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=V65Dpb0xZP2RQHGTP4mw1EAl4bAJEYxRfvEMdfeQuBVzjtpR42MSliJ08O/7pdMY/ XeFfdZxlyoLhs8h/Gy5c5oph3WVLL4ZgssHBLguEsorBfzxT8U8pdC9IjSn9FeDblT l6d+bygkt7KK2yPWYLcMTy15F2I3CVtY08UnBu6o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from eastern.birch.relay.mailchannels.net (eastern.birch.relay.mailchannels.net [23.83.209.55]) by sourceware.org (Postfix) with ESMTPS id 7A8AB386EC59 for ; Wed, 12 May 2021 11:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7A8AB386EC59 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id BA69B1E2E49; Wed, 12 May 2021 11:24:24 +0000 (UTC) Received: from pdx1-sub0-mail-a35.g.dreamhost.com (100-101-162-41.trex.outbound.svc.cluster.local [100.101.162.41]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 18CB91E2560; Wed, 12 May 2021 11:24:24 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a35.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.101.162.41 (trex/6.2.1); Wed, 12 May 2021 11:24:24 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Scare-Unite: 7ad9547a31169427_1620818664337_199574193 X-MC-Loop-Signature: 1620818664337:2591725529 X-MC-Ingress-Time: 1620818664337 Received: from pdx1-sub0-mail-a35.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a35.g.dreamhost.com (Postfix) with ESMTP id C73A886719; Wed, 12 May 2021 04:24:23 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a35.g.dreamhost.com (Postfix) with ESMTPSA id 042B87EF36; Wed, 12 May 2021 04:24:20 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a35 To: libc-alpha@sourceware.org Subject: [PATCH v2] inet: Free result from getaddrinfo Date: Wed, 12 May 2021 16:54:09 +0530 Message-Id: <20210512112409.494492-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <87wns4ns88.fsf@igel.home> References: <87wns4ns88.fsf@igel.home> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Coverity discovered paths where the result from getaddrinfo was not freed. --- inet/rcmd.c | 1 + inet/rexec.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/inet/rcmd.c b/inet/rcmd.c index 452ff7d099..0cfdaee15e 100644 --- a/inet/rcmd.c +++ b/inet/rcmd.c @@ -153,6 +153,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser, free (ahostbuf); ahostbuf = __strdup (res->ai_canonname); if (ahostbuf == NULL) { + freeaddrinfo (res); __fxprintf(NULL, "%s", _("rcmd: Cannot allocate memory\n")); return -1; diff --git a/inet/rexec.c b/inet/rexec.c index bda536723b..064e979d68 100644 --- a/inet/rexec.c +++ b/inet/rexec.c @@ -76,13 +76,13 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass, ahostbuf = __strdup (res0->ai_canonname); if (ahostbuf == NULL) { perror ("rexec: strdup"); - return (-1); + goto bad2; } *ahost = ahostbuf; } else { *ahost = NULL; __set_errno (ENOENT); - return -1; + goto bad2; } ruserpass(res0->ai_canonname, &name, &pass); retry: @@ -90,7 +90,7 @@ retry: s = __socket(res0->ai_family, res0->ai_socktype, 0); if (s < 0) { perror("rexec: socket"); - return (-1); + goto bad2; } if (__connect(s, res0->ai_addr, res0->ai_addrlen) < 0) { if (errno == ECONNREFUSED && timo <= 16) { @@ -100,7 +100,7 @@ retry: goto retry; } perror(res0->ai_canonname); - return (-1); + goto bad; } if (fd2p == 0) { (void) __write(s, "", 1); @@ -116,10 +116,9 @@ retry: socklen_t sa2len; s2 = __socket(res0->ai_family, res0->ai_socktype, 0); - if (s2 < 0) { - (void) __close(s); - return (-1); - } + if (s2 < 0) + goto bad; + __listen(s2, 1); sa2len = sizeof (sa2); if (__getsockname(s2, &sa2.sa, &sa2len) < 0) { @@ -185,6 +184,7 @@ bad: if (port) (void) __close(*fd2p); (void) __close(s); +bad2: freeaddrinfo(res0); return (-1); }