From patchwork Fri Jul 26 12:17:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742741 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94FEF178378 for ; Fri, 26 Jul 2024 12:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996294; cv=none; b=QTajkTT5tLz9ykqXJOxv7Xlw9xl8slfW7v+wRWHx7Q9NYa5nQEq6Vh8i/4FZLEU0tFc6aSjdTyo4sa+AKoc0wJWC4pAujMQ9Ci4TLDEBgy2Hsv986pyZqfWZhTWE1SdsJcIcOlFsJ6jJnjjyGTwTEYee7mw3vVNYuOHnzCY4cbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996294; c=relaxed/simple; bh=FGEooeWHeD4NOrWlUr0g6o3q+d/vNwxkkoAl1aT1wcs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sxzRB5SNLnbdqFK7vzoOY5f2msYtjF7d/9th6tU3Xg5WZAvawCRtRaY0YMwMSv/P+5MOaU2O8VTp83RipDOCysoEWuy6pwEbQOGgecG1BhLh4/8dRV7WhAIKcyEnW7Cybn1+ryxgdngnsnNkWVRfmF9PvjzflCm9uVj2PL1cXmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=EEDtMOvT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mOW/2oTh; arc=none smtp.client-ip=103.168.172.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="EEDtMOvT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mOW/2oTh" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7829C1140205 for ; Fri, 26 Jul 2024 08:18:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 26 Jul 2024 08:18:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996291; x=1722082691; bh=6G5HottkRB NwQgrTc9kobVD/9Cbq5r8DDIkmuMKDOJ0=; b=EEDtMOvTTl1bFqWyOs9KfS731Q lie7EZvLKWU5OOuOql/lMLRxpfxbcDMBWTHevD2sK5pOkB1oSKDbA249vjjy8BZF mmWL/uwataM4q7PGwqWKedtXqJsTagyns3UL1UGHwgFhH8C7tqbzgxk5zB0GLMnE 1okc/t7d20WXjk3LHLoLG8SoQiJi1JnscbVdpsG7od+/vSWTFKcPdVgYTsZ2y7wm C6kC8yGhQjJ2tqEBH3rRZgra7Nmm92zxQZKq9ybPCScI2SoVyL1pBLO/g6PB8QW0 0d6UMiddy/fqyT9esrUzgN2LvjR3tQvqU++1T03IQNQ6eSzYVADibKV9pycg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996291; x=1722082691; bh=6G5HottkRBNwQgrTc9kobVD/9Cbq 5r8DDIkmuMKDOJ0=; b=mOW/2oTh4fRS2UvMVHM8SuL7n90J577FM6IFZJwRusN5 X5aNGxV03JOpWKGmzJJ5e+D/V7rug7ROh4HSVEvjgR4D7kufo2d5hQaFxeHMSg8S 3hMGk9hoCogMBbZmn81sj/1+ljR44c9q3Xyo/5NkmjGZ9oaLgeNCLb5tXk6O0ZFQ LZSAMLPJ9VCtxx9m6enwKCJxJnk1RXjgBsjPo8b7dQ+J/UXvAo9HkCBFjGc8em2c DVgyu20a28Qf+sEMcKk9eqes5yz1vmz4PW31dmr+QUDFQ2yjAgCzLyq3sAbrnTiQ SxdCCq/muRo3Knf7GfnLZwEGStskOzwrGm9OdN0HcA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:18:10 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ca5611e2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:16:49 +0000 (UTC) Date: Fri, 26 Jul 2024 14:17:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 18/23] builtin/credential-cache: fix trivial leaks Message-ID: <2c7a3694903e54dcfa2eadb3b7fa7828da42f5d3.1721995576.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are two trivial leaks in git-credential-cache(1): - We leak the child process in `spawn_daemon()`. As we do not call `finish_command()` and instead let the created process daemonize, we have to clear the process manually. - We do not free the computed socket path in case it wasn't given via `--socket=`. Plug both of these memory leaks. Signed-off-by: Patrick Steinhardt --- builtin/credential-cache.c | 9 +++++++-- t/t0301-credential-cache.sh | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index 3db8df70a9..aaf2f8438b 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -88,6 +88,8 @@ static void spawn_daemon(const char *socket) die_errno("unable to read result code from cache daemon"); if (r != 3 || memcmp(buf, "ok\n", 3)) die("cache daemon did not start: %.*s", r, buf); + + child_process_clear(&daemon); close(daemon.out); } @@ -137,7 +139,8 @@ static void announce_capabilities(void) int cmd_credential_cache(int argc, const char **argv, const char *prefix) { - char *socket_path = NULL; + const char *socket_path_arg = NULL; + char *socket_path; int timeout = 900; const char *op; const char * const usage[] = { @@ -147,7 +150,7 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) struct option options[] = { OPT_INTEGER(0, "timeout", &timeout, "number of seconds to cache credentials"), - OPT_STRING(0, "socket", &socket_path, "path", + OPT_STRING(0, "socket", &socket_path_arg, "path", "path of cache-daemon socket"), OPT_END() }; @@ -160,6 +163,7 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) if (!have_unix_sockets()) die(_("credential-cache unavailable; no unix socket support")); + socket_path = xstrdup_or_null(socket_path_arg); if (!socket_path) socket_path = get_socket_path(); if (!socket_path) @@ -176,6 +180,7 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) else ; /* ignore unknown operation */ + free(socket_path); return 0; } diff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh index c10e35905e..5d5b64205f 100755 --- a/t/t0301-credential-cache.sh +++ b/t/t0301-credential-cache.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='credential-cache tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-credential.sh