NetBSD Problem Report #50199

From www@NetBSD.org  Thu Sep  3 18:13:50 2015
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 43001A6531
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  3 Sep 2015 18:13:50 +0000 (UTC)
Message-Id: <20150903181348.AFBD8A6562@mollari.NetBSD.org>
Date: Thu,  3 Sep 2015 18:13:48 +0000 (UTC)
From: juho.salminen@iki.fi
Reply-To: juho.salminen@iki.fi
To: gnats-bugs@NetBSD.org
Subject: "awk: out of memory in strftime" when calling strftime() with empty format string
X-Send-Pr-Version: www-1.0

>Number:         50199
>Category:       bin
>Synopsis:       "awk: out of memory in strftime" when calling strftime() with empty format string
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 03 18:15:00 +0000 2015
>Closed-Date:    Fri Apr 24 00:27:54 +0000 2020
>Last-Modified:  Fri Apr 24 00:27:54 +0000 2020
>Originator:     Juho Salminen
>Release:        NetBSD-6.1.5
>Organization:
>Environment:
NetBSD isokaijanen.jmos.iki.fi 6.1.5 NetBSD 6.1.5 (ISOKAIJANEN) #0: Thu Mar 19 11:59:14 EET 2015  jmosalmi@isokaijanen.jmos.iki.fi:/usr/netbsd-6.1.5/obj/sys/arch/amd64/compile/ISOKAIJANEN amd64
>Description:
awk fails with error message "out of memory in strftime" when calling strftime() function with an empty format string.

This occurs because it is assumed that return value 0 of strftime() means that the resulting string did not fit into the buffer, even though for an empty format string it really means the length of the resulting string. Thus a bigger and bigger buffer is reallocated until memory exhausts.

>How-To-Repeat:
[jmosalmi@isokaijanen ~]$ awk 'BEGIN {strftime("")}'
awk: out of memory in strftime
 source line number 1
[jmosalmi@isokaijanen ~]$ 
>Fix:
--- src/external/historical/nawk/dist/run.c.~1.4.2.1.~  2012-07-12 22:24:21.000000000 +0300
+++ src/external/historical/nawk/dist/run.c     2015-09-03 20:55:44.000000000 +0300
@@ -1650,7 +1650,7 @@
                do {
                        if ((buf = realloc(buf, (sz *= 2))) == NULL)
                                FATAL("out of memory in strftime");
-               } while(strftime(buf, sz, fmt, tm) == 0);
+               } while(strftime(buf, sz, fmt, tm) == 0 && fmt[0] != '\0');

                y = gettemp();
                setsval(y, buf);

>Release-Note:

>Audit-Trail:
From: "Mateusz Kocielski" <shm@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50199 CVS commit: src/external/historical/nawk/dist
Date: Tue, 3 Nov 2015 14:15:08 +0000

 Module Name:	src
 Committed By:	shm
 Date:		Tue Nov  3 14:15:08 UTC 2015

 Modified Files:
 	src/external/historical/nawk/dist: run.c

 Log Message:
 PR/50199 - fix for strftime called with empty string.
 Patch written by Juho Salminen


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/external/historical/nawk/dist/run.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Mateusz Kocielski <shm@digitalsun.pl>
To: gnats-bugs@netbsd.org
Cc: juho.salminen@iki.fi
Subject: Re: bin/50199
Date: Tue, 3 Nov 2015 14:27:47 +0000

 Hello,

  thanks for your patch and detailed analysis! I've committed it.

  Best Regards,
  Mateusz Kocielski

State-Changed-From-To: open->needs-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 01 Oct 2016 17:41:41 +0000
State-Changed-Why:
Committed a year ago, but was filed against -6 so should get pulled up.


State-Changed-From-To: needs-pullups->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Fri, 24 Apr 2020 00:27:54 +0000
State-Changed-Why:
No more pullups for netbsd-6. Thanks for the report! It is in all supported releases.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.