Comment 7 for bug 50563

Revision history for this message
In , Vassilis Pandis (pandisv) wrote :

Hello,

this is a bug originally reported at https://bugs.launchpad.net/bugs/50563 . An
Ubuntu user reported the following:

"This segfaults on Ubuntu Dapper:

#define _XOPEN_SOURCE
#include <time.h>
int main() {
  struct tm tm;
  strptime("2004", "%Y", &tm); /* Segfault. */
  return 0;
}

This does not:

#define _XOPEN_SOURCE
#include <time.h>
int main() {
  struct tm tm;
  strptime("2004-01-01", "%Y-%m-%d", &tm); /* OK. */
  strptime("2004-01", "%Y-%m", &tm); /* OK. */
  return 0;
}

Internally, strptime() sets up a "struct tm" when parsing the date string. If
both the month and day-of-month are not present, two fields in that struct are
left uninitialized, and the segfault occurs when the uninitialized values are
used in an array lookup in time/strptime_l.c:day_of_the_week().

I have a patch for this, but cannot be sure that it works, because I don't have
enough disk space or CPU time for a glibc build."

Unfortunately, we haven't been able to contact the user for a patch. At any
rate, it would be nice if this were fixed. Thanks!