From: Cedric Duval Date: Fri, 8 Sep 2006 09:14:45 +0000 (+0000) Subject: * parse_date_string(): don't modify string argument in place, since most X-Git-Tag: upstream/0.6.1~2^2~80 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=84b0eeb8e0b3863b517daa5a2137f07e7680f50e;p=pkg%2Fabook.git * parse_date_string(): don't modify string argument in place, since most if not all of the time this function is applied on a database entry. Too prone to dangerous oversight. * fixed bsdcal export not checking for validity of parsed date. --- diff --git a/edit.c b/edit.c index 940a57d..c66b92c 100644 --- a/edit.c +++ b/edit.c @@ -250,12 +250,10 @@ editor_print_data(int tab, int item) int day, month, year; char buf[64]; - /* put raw representation of date in buf */ find_field_number(cur->field->key, &nb); - if((str = db_fget_byid(item, nb)) != NULL) - strncpy(buf, str, sizeof(buf)); - - if(str && parse_date_string(buf, &day, &month, &year)) { + str = db_fget_byid(item, nb); + + if(parse_date_string(str, &day, &month, &year)) { /* put locale representation of date in buf */ locale_date(buf, sizeof(buf), year, month, day); mvwaddnstr(editw, y, TAB_COLON_POS + 2, buf, @@ -475,11 +473,17 @@ static int is_valid_date(const int day, const int month, const int year) } int -parse_date_string(char *s, int *day, int *month, int *year) +parse_date_string(char *str, int *day, int *month, int *year) { int i = 0; - char *p = s; - assert(s && day && month && year); + char buf[12], *s, *p; + + assert(day && month && year); + + if(!str || !*str) + return FALSE; + + p = s = strncpy(buf, str, sizeof(buf)); if(*s == '-' && *s++ == '-') { /* omitted year */ *year = 0; @@ -501,7 +505,7 @@ parse_date_string(char *s, int *day, int *month, int *year) } p = s; } else - return FALSE; + return FALSE; } if (i != 2 || !*p) @@ -515,14 +519,11 @@ parse_date_string(char *s, int *day, int *month, int *year) static void edit_date(int item, int nb) { - int i, date[3], old = FALSE; - char buf[12], *s = db_fget_byid(item, nb); + int i, date[3], old; + char *s = db_fget_byid(item, nb); char *field[] = { N_("Day: "), N_("Month: "), N_("Year (optional): ") }; - if(s) { - strncpy(buf, s, sizeof(buf)); - old = parse_date_string(buf, &date[0], &date[1], &date[2]); - } + old = parse_date_string(s, &date[0], &date[1], &date[2]); for(i = 0; i < 3; i++) { s = (old && date[i]) ? strdup_printf("%d", date[i]) : NULL; diff --git a/filter.c b/filter.c index 04b9a3b..0bdc4b9 100644 --- a/filter.c +++ b/filter.c @@ -1890,7 +1890,8 @@ bsdcal_export_database(FILE *out, struct db_enumerator e) char *anniversary = db_fget(e.item, ANNIVERSARY); if(anniversary) { - parse_date_string(anniversary, &day, &month, &year); + if(!parse_date_string(anniversary, &day, &month, &year)) + continue; fprintf(out, _("%02d/%02d\tAnniversary of %s\n"),