Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Mon, 19 Dec 2022 13:50:58 -0500
From: Rich Felker <dalias@...c.org>
To: Rob Landley <rob@...dley.net>
Cc: musl@...ts.openwall.com
Subject: Re: strftime trailing %

On Mon, Dec 19, 2022 at 12:06:38PM -0600, Rob Landley wrote:
> In glibc and bionic a trailing % in strftime() acts like printf, I.E. it's a
> literal "%". But in musl, it's an error that returns length 0. Test program:
> 
> #include <stdio.h>
> #include <time.h>
> 
> int main(int argc, char *argv[])
> {
>   char buf[256];
>   struct tm tm = {0};
> 
>   strftime(buf, sizeof(buf), "hello %", &tm);
>   return printf("%s\n", buf);
> }
> 
> 
> The fix looks simple enough, although I haven't built a toolchain with it yet:
> 
> --- a/src/time/strftime.c
> +++ b/src/time/strftime.c
> @@ -225,7 +225,7 @@ size_t __strftime_l(char *restrict s, size_t n, const char
> *restrict f, const st
>  			s[l] = 0;
>  			return l;
> 		}
> -		if (*f != '%') {
> +		if (*f != '%' || !f[1]) {
>  			s[l++] = *f;
>  			continue;
>  		}
> 
> This is breaking a toybox test for the "date" command.

Is this supposed to be well-defined, either for the date command or
for strftime? I don't see where it's explicitly covered in any of the
spec so if it's defined or undefined/unspecified would presumably fall
out as a consequence of how conversion specifications and ordinary
characters are defined.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.