From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hedgehog.birch.relay.mailchannels.net (hedgehog.birch.relay.mailchannels.net [23.83.209.81]) by sourceware.org (Postfix) with ESMTPS id 0F6873858C52 for ; Fri, 5 May 2023 14:56:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F6873858C52 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.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 3C0B05C160D; Fri, 5 May 2023 14:56: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 9FD705C0608; Fri, 5 May 2023 14:56:33 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1683298593; a=rsa-sha256; cv=none; b=ew6K9W0kR3bUwnJS9k5Hn+UfF5/KcHLUtJHWRe6TfrumeNjm4HL58iYcZFIZlvql91JgM+ uFMTPxvypaQGzcRMETpxDBE3WoYbMkgWhdTlHlCG+AveqCZOptBeKEJeW0cqGVw1ywv5n+ zA5SzcJVfO6DpfaEW5Esus4FSja6MG7HbQ8UP34Pm+Uwya7ApSPyixDUzNjTJ0Ne/Bqtij 1Zg7h0aPT7Jzdt+G1giypkrLnlD1vj7ig/Xok+ub1v3P7Vr5hkqgdZU8nz5K50/SymT0q6 EExwoPMIiG6ohSFEXek/FzfzRGCxiqXE2MKgqbcmOCbkSajL2coHJa42ykptWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1683298593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KtD7bXpnjWuKaQjVO3b3LL4zSMtposfuC3Xx7ObpmGU=; b=AzOyQ7E07NX7hTqhR2SFCCaYKgQtc4PtgWQzAApoUBRqhs52+AU3tALWlw7hAO1y5qfEMF 9Em26mwF3lPG3aEi5egDgxY9f533c0fQ6gaUUiNLcFF0XrVH+k6Uo88PN6Ei5+7haufh6r nsKfbF75fGJ0QEVJIIk5zWN6ZbW3PYNaiwYhimaDv2AJkJGVNuwDYqa/jbtTZHLyfDwHX6 bf0w1YayWmODxjJ21s5znuiJbngpbAqytEW2s93nvH/1UEPtFVYdyhOIhj2yQ1tN77GtJY 1MAtrPj4adZbS+ptdfcv/fSDQbPyZaiReQRm3zgbLBm1XD9boZdW0NofiKWsBw== ARC-Authentication-Results: i=1; rspamd-5c4597ccb8-df6vf; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.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-Skirt-Language: 7a6cf6175c030b1e_1683298593983_1252869557 X-MC-Loop-Signature: 1683298593983:4070612095 X-MC-Ingress-Time: 1683298593983 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.109.138.49 (trex/6.7.2); Fri, 05 May 2023 14:56:33 +0000 Received: from fedora.redhat.com (bras-vprn-toroon4834w-lp130-09-174-91-45-80.dsl.bell.ca [174.91.45.80]) (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) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4QCYfn1khzz1p; Fri, 5 May 2023 07:56:33 -0700 (PDT) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [committed] time: Remove alloca() from getdate Date: Fri, 5 May 2023 10:56:28 -0400 Message-Id: <20230505145628.1747318-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1173.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL,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: From: Joe Simmons-Talbott Reduce the usage of alloca() to the bare minimum to avoid the potential for stack overflow. Use __strndup to simplify the code. Reviewed-by: Siddhesh Poyarekar --- I had to fix up a whitespace issue before committing, this is what finally went in. Thanks, Sid time/getdate.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/time/getdate.c b/time/getdate.c index c5c8378707..1dcbd77188 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; + string = instr; } line = NULL; -- 2.40.0