Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Mon, 19 Dec 2022 12:06:38 -0600
From: Rob Landley <>
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;

This is breaking a toybox test for the "date" command.


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.