From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66]) by sourceware.org (Postfix) with ESMTPS id 4581A3858C2F for ; Tue, 16 May 2023 22:01:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4581A3858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 4AE6B3C09FA1A; Tue, 16 May 2023 15:01:00 -0700 (PDT) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id o6XzE7Ve6Yhd; Tue, 16 May 2023 15:01:00 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 007133C09FA1B; Tue, 16 May 2023 15:01:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 007133C09FA1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1684274460; bh=WCqpRx8R7KSpjXrTOFVMg+6cWbQXOJ7RnCjysWfmPQU=; h=Message-ID:Date:MIME-Version:To:From; b=U9ZXAixBZZMt2U0t6+8BAZE7Cnv3ZRTCMtNujZtY8wKQTNgyWBnH4U26jRA0TAA0k bYvuut5581Gxwucl6QnKiRTWG/0t0p/muC5j4bC9pcp0XRwFMQ+w36W8sMcBc1hPf8 ahfyuhAeuUTBR47O36rzIZxFd4RXj828h3iAH2Lhpzuw2JNDL9K7oyxxxbx3cYynmx dV14r0cQ4qK5DXa9Je2axAUoQ9RZpLK3tAqEb7khTe+7yRYwlwbfx/NQsqQULMGBdf fCRlbKpicmeurm4SmEf2MbbBs2NFaP5GkY6pHeic71XUszHPMTy7iQcRdZFMp7eKCH Mm5K/KCNgN8DA== X-Virus-Scanned: amavisd-new at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id aDhaLLpqH0nJ; Tue, 16 May 2023 15:00:59 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id D8A723C02213D; Tue, 16 May 2023 15:00:59 -0700 (PDT) Message-ID: Date: Tue, 16 May 2023 15:00:59 -0700 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] time: strftime_l: Use malloc rather than an unbounded alloca. Content-Language: en-US To: Adhemerval Zanella Netto , Joe Simmons-Talbott , libc-alpha@sourceware.org References: <20230510195946.3728273-1-josimmon@redhat.com> From: Paul Eggert Organization: UCLA Computer Science Department In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,JMQ_SPF_NEUTRAL,NICE_REPLY_A,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 5/16/23 12:28, Adhemerval Zanella Netto via Libc-alpha wrote: > Do we have a practical maximum size for the abbreviate timezone name? The > internal tz_rule 'name' field is just a pointer, but I think all timezones > uses a maximum name size. In current TZDB data the longest abbreviation has four bytes (e.g., "AKST", "NZST"). Before TZDB release 2016g (2016-09-13) the longest was 48 bytes, for the Factory zone's "Local time zone must be set--see zic manual page" abbreviation. Although the TZif file format's limit is 2**32 - 1 bytes, the 'zic' command won't process TZif files with abbreviations longer than about 2000 bytes, due to its internal input line buffer. There is a limit even if you use long strings in TZ environment variables, as glibc strftime is buggy when a buffer contains more than INT_MAX bytes (it uses 'int' to store byte counts). This means you can't effectively use a time zone abbreviation longer than about 2**31 - 1 bytes with glibc, even on 64-bit platforms. For example, a program like the one shown below won't work with glibc. For what it's worth, _POSIX_TZNAME_MAX is 6, that is, every POSIX platform must support at least 6 bytes. #include #include #include #include int main () { size_t Xs = (1LL << 32) + 1; char *tzbuf = malloc (sizeof "TZ=" - 1 + Xs + sizeof "0"); if (!tzbuf) return perror ("malloc tzbuf"), 1; size_t strftimebufsize = Xs + 2; char *strftimebuf = malloc (strftimebufsize); if (!strftimebuf) return perror ("malloc strftimebuf"), 1; strcpy (tzbuf, "TZ="); memset (tzbuf + 3, 'X', Xs); strcpy (tzbuf + 3 + Xs, "0"); if (putenv (tzbuf)) return perror ("putenv"), 1; time_t t0 = 0; struct tm *tm = localtime (&t0); if (!tm) return perror ("localtime"), 1; size_t nbytes = strftime (strftimebuf, strftimebufsize, "%Z", tm); if (!nbytes) return perror ("strftime"), 1; if (puts (strftimebuf) < 0) return perror ("puts"), 1; if (fclose (stdout) < 0) return perror ("fclose"), 1; return 0; }