NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/50199: "awk: out of memory in strftime" when calling strftime() with empty format string
>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: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Sep 03 18:15:00 +0000 2015
>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@localhost:/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);
Home |
Main Index |
Thread Index |
Old Index