From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#30738: Invalid timezone (tzalloc failure) treated as out-of-memory Date: Sun, 11 Mar 2018 00:33:03 -0800 Organization: UCLA Computer Science Department Message-ID: References: <1370cc81-6aea-ed58-fcc0-1adc32f4252c@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9EDCB85ED47E0C4B3150A0F5" X-Trace: blaine.gmane.org 1520757132 18594 195.159.176.226 (11 Mar 2018 08:32:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 11 Mar 2018 08:32:12 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Cc: 30738-done@debbugs.gnu.org To: Valery Ushakov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Mar 11 09:32:08 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1euwOi-0004eB-W4 for geb-bug-gnu-emacs@m.gmane.org; Sun, 11 Mar 2018 09:32:05 +0100 Original-Received: from localhost ([::1]:53511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euwQl-0008L5-Ut for geb-bug-gnu-emacs@m.gmane.org; Sun, 11 Mar 2018 04:34:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euwQf-0008Ju-DM for bug-gnu-emacs@gnu.org; Sun, 11 Mar 2018 04:34:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euwQc-0002T2-9n for bug-gnu-emacs@gnu.org; Sun, 11 Mar 2018 04:34:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46767) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1euwQc-0002So-4B for bug-gnu-emacs@gnu.org; Sun, 11 Mar 2018 04:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1euwQb-0002zr-RB for bug-gnu-emacs@gnu.org; Sun, 11 Mar 2018 04:34:01 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Mar 2018 08:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 30738 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 30738@debbugs.gnu.org, eggert@cs.ucla.edu, uwe@stderr.spb.ru Original-Received: via spool by 30738-done@debbugs.gnu.org id=D30738.152075719111446 (code D ref 30738); Sun, 11 Mar 2018 08:34:01 +0000 Original-Received: (at 30738-done) by debbugs.gnu.org; 11 Mar 2018 08:33:11 +0000 Original-Received: from localhost ([127.0.0.1]:54662 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1euwPn-0002yX-FW for submit@debbugs.gnu.org; Sun, 11 Mar 2018 04:33:11 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41984) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1euwPl-0002yI-VG for 30738-done@debbugs.gnu.org; Sun, 11 Mar 2018 04:33:10 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 983401616C5; Sun, 11 Mar 2018 00:33:04 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id jsUBRLTFLQnb; Sun, 11 Mar 2018 00:33:03 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id AF59F1616D3; Sun, 11 Mar 2018 00:33:03 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Wii6AD47R_rw; Sun, 11 Mar 2018 00:33:03 -0800 (PST) Original-Received: from [192.168.1.9] (unknown [47.154.30.119]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 897E11616C5; Sun, 11 Mar 2018 00:33:03 -0800 (PST) In-Reply-To: <1370cc81-6aea-ed58-fcc0-1adc32f4252c@cs.ucla.edu> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:144122 Archived-At: This is a multi-part message in MIME format. --------------9EDCB85ED47E0C4B3150A0F5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit [resending, I hope to the right place this time] Thanks for reporting the problem. I have installed the attached two patches, which I think should fix the problem so I'm closing the bug report. Please give them a try on NetBSD (as I typically don't use NetBSD). --------------9EDCB85ED47E0C4B3150A0F5 Content-Type: text/x-patch; name="0001-Fix-minor-timezone-memory-leak.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-minor-timezone-memory-leak.patch" >From f7c07930b581b1bcfdfb1874b6883233516bdf11 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 16 May 2017 14:19:36 -0700 Subject: [PATCH] Fix minor timezone memory leak * src/editfns.c (wall_clock_tz): Remove; unused. --- src/editfns.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/editfns.c b/src/editfns.c index ecb8e3f083..75eb75a729 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -81,10 +81,8 @@ static Lisp_Object styled_format (ptrdiff_t, Lisp_Object *, bool); enum { tzeqlen = sizeof "TZ=" - 1 }; -/* Time zones equivalent to current local time, to wall clock time, - and to UTC, respectively. */ +/* Time zones equivalent to current local time and to UTC, respectively. */ static timezone_t local_tz; -static timezone_t wall_clock_tz; static timezone_t const utc_tz = 0; /* The cached value of Vsystem_name. This is used only to compare it @@ -269,7 +267,6 @@ init_editfns (bool dumping) /* Set the time zone rule now, so that the call to putenv is done before multiple threads are active. */ - wall_clock_tz = xtzalloc (0); tzlookup (tz ? build_string (tz) : Qwall, true); pw = getpwuid (getuid ()); -- 2.14.3 --------------9EDCB85ED47E0C4B3150A0F5 Content-Type: text/x-patch; name="0001-Port-to-NetBSD-tzalloc.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Port-to-NetBSD-tzalloc.patch" >From 46844ad78968cd804d0e5fc98ce49b46b3d8a53d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 11 Mar 2018 00:18:34 -0800 Subject: [PATCH] Port to NetBSD tzalloc Problem reported by Valery Ushakov (Bug#30738). * src/editfns.c (xtzalloc): Remove. (invalid_time_zone_specification): New function. (tzlookup): Port to NetBSD, where tzalloc can fail when the TZ string has an invalid value. --- src/editfns.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/editfns.c b/src/editfns.c index 3a34dd0980..debe10572d 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -117,14 +117,10 @@ emacs_mktime_z (timezone_t tz, struct tm *tm) return t; } -/* Allocate a timezone, signaling on failure. */ -static timezone_t -xtzalloc (char const *name) +static _Noreturn void +invalid_time_zone_specification (Lisp_Object zone) { - timezone_t tz = tzalloc (name); - if (!tz) - memory_full (SIZE_MAX); - return tz; + xsignal2 (Qerror, build_string ("Invalid time zone specification"), zone); } /* Free a timezone, except do not free the time zone for local time. @@ -205,9 +201,15 @@ tzlookup (Lisp_Object zone, bool settz) } } else - xsignal2 (Qerror, build_string ("Invalid time zone specification"), - zone); - new_tz = xtzalloc (zone_string); + invalid_time_zone_specification (zone); + + new_tz = tzalloc (zone_string); + if (!new_tz) + { + if (errno == ENOMEM) + memory_full (SIZE_MAX); + invalid_time_zone_specification (zone); + } } if (settz) -- 2.14.3 --------------9EDCB85ED47E0C4B3150A0F5--