From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id A25011F8C6 for ; Wed, 8 Sep 2021 09:42:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348023AbhIHJnj (ORCPT ); Wed, 8 Sep 2021 05:43:39 -0400 Received: from cloud.peff.net ([104.130.231.41]:41594 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347717AbhIHJni (ORCPT ); Wed, 8 Sep 2021 05:43:38 -0400 Received: (qmail 22995 invoked by uid 109); 8 Sep 2021 09:42:30 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 08 Sep 2021 09:42:30 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 25067 invoked by uid 111); 8 Sep 2021 09:42:31 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 08 Sep 2021 05:42:31 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 8 Sep 2021 05:42:28 -0400 From: Jeff King To: Junio C Hamano Cc: git@vger.kernel.org Subject: Re: [PATCH] hash-object: prefix_filename() returns allocated memory these days Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Tue, Sep 07, 2021 at 03:10:22PM -0700, Junio C Hamano wrote: > Back when a1be47e4 (hash-object: fix buffer reuse with --path in a > subdirectory, 2017-03-20) was written, the prefix_filename() helper > used a static piece of memory to the caller, making the caller > responsible for copying it, if it wants to keep it across another > call to the same function. Two callers of the prefix_filename() in > hash-object were made to xstrdup() the value obtained from it. > > But in the same series, when e4da43b1 (prefix_filename: return newly > allocated string, 2017-03-20) changed the rule to gave the caller > possession of the memory, we forgot to revert one of the xstrdup() > changes, allowing the returned value to leak. Good catch. The patch looks obviously correct to me. -Peff