Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: segfault in strftime



On Fri, 26 Feb 2010 16:07:49 +0100
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> > $ strftime "%a %d.%m.%Y %H:%M:%S" -1
> > strftime: -1: success
> 
> Concerning this one:
> 
>     secs = (time_t)strtoul(argv[1], &endptr, 10);
>     if (secs == (time_t)ULONG_MAX) {
>         zwarnnam(nam, "%s: %e", argv[1], errno);
>         return 1;
>     } else if (*endptr != '\0') {
>         zwarnnam(nam, "%s: invalid decimal number", argv[1]);
>         return 1;
>     }
> 
> ULONG_MAX is not necessarily an error! You need to check errno.

I hope we don't need to handle the case sizeof(time_t) > sizeof(unsigned
long).  It's certainly not typical.

Index: Src/Modules/datetime.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/datetime.c,v
retrieving revision 1.19
diff -p -u -r1.19 datetime.c
--- Src/Modules/datetime.c	26 Feb 2010 14:25:05 -0000	1.19
+++ Src/Modules/datetime.c	26 Feb 2010 15:15:12 -0000
@@ -111,8 +111,9 @@ bin_strftime(char *nam, char **argv, Opt
     if (OPT_ISSET(ops, 'r'))
 	return reverse_strftime(nam, argv, scalar, OPT_ISSET(ops, 'q'));
 
+    errno = 0;
     secs = (time_t)strtoul(argv[1], &endptr, 10);
-    if (secs == (time_t)ULONG_MAX) {
+    if (secs == (time_t)ULONG_MAX && errno != 0) {
 	zwarnnam(nam, "%s: %e", argv[1], errno);
 	return 1;
     } else if (*endptr != '\0') {



-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author