Kaynağa Gözat

strftime: fix breakage in last change (uninitialized pointer access)

commit f47a5d400b8ffa26cfc5b345dbff52fec94ac7f3 overlooked that
strtoul was responsible for setting p to a const-laundered copy of the
format string pointer f, even in the case where there was no number to
parse. by making the call conditional on isdigit, that copy was lost.

the logic here is a mess and should be cleaned up, but for now, this
seems to be the least invasive change that undoes the breakage.
Rich Felker 1 yıl önce
ebeveyn
işleme
4a16ddf53e
1 değiştirilmiş dosya ile 6 ekleme ve 1 silme
  1. 6 1
      src/time/strftime.c

+ 6 - 1
src/time/strftime.c

@@ -234,7 +234,12 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st
 		pad = 0;
 		if (*f == '-' || *f == '_' || *f == '0') pad = *f++;
 		if ((plus = (*f == '+'))) f++;
-		width = isdigit(*f) ? strtoul(f, &p, 10) : 0;
+		if (isdigit(*f)) {
+			width = strtoul(f, &p, 10);
+		} else {
+			width = 0;
+			p = (void *)f;
+		}
 		if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') {
 			if (!width && p!=f) width = 1;
 		} else {