| 
  | 
Message-ID: <a8b5e402-e92a-080f-dd4f-c2c70ba756d2@landley.net>
Date: Mon, 19 Dec 2022 12:06:38 -0600
From: Rob Landley <rob@...dley.net>
To: musl@...ts.openwall.com
Subject: strftime trailing %
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.
Rob
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.