From patchwork Fri Mar 25 21:38:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 663241 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2PLcU4g001701 for ; Fri, 25 Mar 2011 21:38:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755342Ab1CYViW (ORCPT ); Fri, 25 Mar 2011 17:38:22 -0400 Received: from mail-gx0-f174.google.com ([209.85.161.174]:45717 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755134Ab1CYViV (ORCPT ); Fri, 25 Mar 2011 17:38:21 -0400 Received: by gxk21 with SMTP id 21so620854gxk.19 for ; Fri, 25 Mar 2011 14:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:subject:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version:content-type :content-transfer-encoding; bh=D0BKddGM2L/cwoJhtnEm5lk6OVnDET5gGlTynUk85Js=; b=iWtUJXxwAxy9c4XFsPLaQlCtwVyxACxKEZhes2wjODPucbYVz6XCZtUPEqFwI2frBb w09mK2PJQQxwOil453rX0OrtRSY4db0XNsxw6yrxclrJbvj1WwPJH8urywrCaJkqp8Ku vzmDGz14w9YSwoIGPWP8zYBaPjTqc1FJllLus= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:subject:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; b=QXSWPmTde9H3gIx+xrIon3Zq082GHebnTzWEtDbnD8rU/2K0sTVjEF70z1bZBVko3d 0Eooj4uLjMukDkEdVh5UHAIqBlacLP68Y4eIVrdw8RnRd8Knvw5IyNttx9P/DLPmHC5i 6nKIzgBijcDPfVb7GodAm/uK0P+OzNAfrhaCA= Received: by 10.236.62.193 with SMTP id y41mr1874169yhc.4.1301089100960; Fri, 25 Mar 2011 14:38:20 -0700 (PDT) Received: from matisse.1015granger.net (adsl-99-26-161-222.dsl.sfldmi.sbcglobal.net [99.26.161.222]) by mx.google.com with ESMTPS id u5sm692400yhn.51.2011.03.25.14.38.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 25 Mar 2011 14:38:19 -0700 (PDT) From: Chuck Lever Subject: [PATCH 1/3] mount.nfs: Don't leak socket in nfs_ca_sockname() To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Date: Fri, 25 Mar 2011 17:38:06 -0400 Message-ID: <20110325213806.27166.56852.stgit@matisse.1015granger.net> In-Reply-To: <20110325213559.27166.71461.stgit@matisse.1015granger.net> References: <20110325213559.27166.71461.stgit@matisse.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 25 Mar 2011 21:38:37 +0000 (UTC) diff --git a/utils/mount/network.c b/utils/mount/network.c index 9b6504d..52a5389 100644 --- a/utils/mount/network.c +++ b/utils/mount/network.c @@ -1095,7 +1095,7 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen, .sin6_family = AF_INET6, .sin6_addr = IN6ADDR_ANY_INIT, }; - int sock; + int sock, result = 0; sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) @@ -1103,28 +1103,26 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen, switch (sap->sa_family) { case AF_INET: - if (bind(sock, SAFE_SOCKADDR(&sin), sizeof(sin)) < 0) { - close(sock); - return 0; - } + if (bind(sock, SAFE_SOCKADDR(&sin), sizeof(sin)) < 0) + goto out; break; case AF_INET6: - if (bind(sock, SAFE_SOCKADDR(&sin6), sizeof(sin6)) < 0) { - close(sock); - return 0; - } + if (bind(sock, SAFE_SOCKADDR(&sin6), sizeof(sin6)) < 0) + goto out; break; default: errno = EAFNOSUPPORT; - return 0; + goto out; } - if (connect(sock, sap, salen) < 0) { - close(sock); - return 0; - } + if (connect(sock, sap, salen) < 0) + goto out; - return !getsockname(sock, buf, buflen); + result = !getsockname(sock, buf, buflen); + +out: + close(sock); + return result; } /*