From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hamster.birch.relay.mailchannels.net (hamster.birch.relay.mailchannels.net [23.83.209.80]) by sourceware.org (Postfix) with ESMTPS id 96F833857735 for ; Tue, 2 May 2023 16:38:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96F833857735 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org 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 E2E913E1205; Tue, 2 May 2023 16:38:34 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 822CA3E11B0; Tue, 2 May 2023 16:38:34 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1683045514; a=rsa-sha256; cv=none; b=bNmVJAkVvqgVeGp6A8cYUectjNNMaDjNHOirX7ZOFxW0QLPaeHS+7PvBRN7Z0kjsnZMG4e 0Pdq4/jCF4P5+JI3+rTg951YhFwYtmCiOvcNKePpr19ElOiiDJ13SY2mZQEXKZKYHmk61x zOzDh/puwxp+fcf+TLS6heK/tvHMMpHbJzPvFXd2cAdLfCee8LM78v8B4ZaOUcHr2xyz+n T26i4STuyadqmbHAgiRP07yKaqkhJ+31sR80i8SUYX2L6GDaENmeMdMwEvZSTspeUIYlRI YGuAhSR2Nxuv55o/YLDKFm62thmF1tj8mPUerrCA/dFNuFo6zH5jkovS6nA3Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1683045514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6URfrrYjLJHT+KXPr+KQjwBFdGmgsWuw7h9OnLClZA8=; b=6uVOJ4ic4kETgtspCASKHXXx+ou2Hh8GLkKcCP+lAaDkbhVTP0Yo39SDdTiFzQ7Qkntyyp Za0AmvpOorbEISyu9HyyjbSqTOybLixTFAP9TsU8bmRa4F38RxXfceZpqWvodMUc5Yo5pr AYFduX6gHKMJk48o2J04ylkSih7j2598lis8vqZIbBw5qK9ADNwOz3CLCxcd0491nFhe5W HQUknvh9r2ov9T3QtIn4Kyf7OlmDJeJfX2g0fRks1BnYyJGk1Y+M1b3ttKTOYL9T3Er9KB 3Cz1UyQTzdCYbj5mGbyOhc1EafdhmVRE6LYKj6cnIS7Ats82fOwNXsd0hXOK3w== ARC-Authentication-Results: i=1; rspamd-548d6c8f77-jm9l4; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Whimsical-Shrill: 7a13b17662b853e7_1683045514757_2374543135 X-MC-Loop-Signature: 1683045514757:3958564921 X-MC-Ingress-Time: 1683045514757 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.125.42.148 (trex/6.7.2); Tue, 02 May 2023 16:38:34 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-09-174-91-45-80.dsl.bell.ca [174.91.45.80]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4Q9m3t11cTzRx; Tue, 2 May 2023 09:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1683045514; bh=6URfrrYjLJHT+KXPr+KQjwBFdGmgsWuw7h9OnLClZA8=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=ZjMv98RK8b2cDOterMCzVrtLuX2EZvsFIIhfcuD//aKGjuixrHPq/Mf2aMclfu2Vw Lx2nxKIr1ojuOLu3PRBa3K0G2zl1VcalSen3yXwpJg6UrQO0JJnyuXLT8MLxudYX/B 89UuQMQ2+2SKR7MMiBIQ0kXg2wMKmi0TAooTSeV8VGx7azQghbvnoZUmX4PQBBhz5N GKgbDtZ41A0q6KDVWF62IOpzGMbXtKHf5pMHfplC5p5axeXBvwiGHN8uPFvaCXmvfk L232kIE2tTU77mnofpsyP7aaH/X+I3ZRpxpBjzTckb7WaccEalh/QC6RpPjdUd16na IS+JUp5CZPF5A== Message-ID: <1fd4da71-9a2c-87c7-6977-5f7c0aaf2837@gotplt.org> Date: Tue, 2 May 2023 12:38:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v2] time: Remove alloca() from getdate Content-Language: en-US To: Joe Simmons-Talbott , libc-alpha@sourceware.org References: <20230426152244.1981882-1-josimmon@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230426152244.1981882-1-josimmon@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3038.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-04-26 11:22, Joe Simmons-Talbott via Libc-alpha wrote: > Changes to v1: > * Add error handling for __strndup() > > --8<-- > Reduce the usage of alloca() to the bare minimum to avoid the potential > for stack overflow. Use __strndup to simplify the code. > --- > time/getdate.c | 23 +++++------------------ > 1 file changed, 5 insertions(+), 18 deletions(-) +1, I don't see a good reason to prematurely optimize this path given that file operations on $DATEMSK should dominate any profile in this function. LGTM. Reviewed-by: Siddhesh Poyarekar > > diff --git a/time/getdate.c b/time/getdate.c > index c5c8378707..2f0ebbe097 100644 > --- a/time/getdate.c > +++ b/time/getdate.c > @@ -26,7 +26,6 @@ > #include > #include > #include > -#include > > #define TM_YEAR_BASE 1900 > > @@ -153,26 +152,14 @@ __getdate_r (const char *string, struct tm *tp) > > if (inlen < oldlen) > { > - bool using_malloc = false; > - > - if (__libc_use_alloca (inlen + 1)) > - instr = alloca (inlen + 1); > - else > + instr = __strndup(string, inlen); > + if (instr == NULL) > { > - instr = malloc (inlen + 1); > - if (instr == NULL) > - { > - fclose (fp); > - return 6; > - } > - using_malloc = true; > + fclose(fp); > + return 6; > } > - memcpy (instr, string, inlen); > - instr[inlen] = '\0'; > + > string = instr; > - > - if (!using_malloc) > - instr = NULL; > } > > line = NULL;