This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix BZ 18985 out of bounds access in strftime


Paul Pluzhnikov wrote:
... but formats the other values, e.g. it can print something like

   memset (tp, 0, sizeof (*tp));
   tp->tm_hour = 1024;

   strftime(..., "%H %I", tp);  // produces "1024 04"

that doesn't seem very desirable.

That helps the programmer more than returning 0 would. I occasionally need to format hours outside the 00-23 range, e.g., the "26" in the POSIX-style TZ string "IST-2IDT,M3.4.4/26,M10.5.0" for Israel's current daylight-saving rules. And even if the 1024 is a bug, one can debug it more easily by seeing the 1024 in the output than by puzzling over a 0 return code.

Although as Martin Sebor mentions we could pretend that strftime is generating an infinitely-long string and use this pretence to return 0, that would be less useful not to mention less compatible with existing practice.

Anyway, I'll send a patch to eliminate just the crashes on OOB tm_mon
and tm_wday.

Don't forget out-of-range tm_isdst: there's one place the code has undefined behavior if tm_isdst exceeds 1.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]