Browse Source

Fix CopyArrivalDate on platforms without glibc

strptime(3)'s "%d" day of the month conversion specifier does not accept
leading blanks in case of single digit numbers.  "%e" does that.

While implementation details and differences between the two
day-of-month conversion specifiers vary, none of the major libcs
(incl. OpenBSD, FreeBSD, Illumos, musl) consume a leading blank for "%d"
except glibc, which consumes any number of spaces like in the "%e" case.

Using "%e" ensures that date strings like " 4-Mar-2018 16:49:25 -0500"
are successfully parsed by all major implementations in compliance to
X/Open Portability Guide Issue 4, Version 2 ("XPG4.2").  musl is now the
only one that still treats "%d" and "%e" without stripping any space.

Issue analysed and reported by Evan Silberman <evan@jklol.net> who found
mbsync 1.3.0 on OpenBSD 6.4 to fail with `CopyArrivalDate' set when
syncing mails with the above mentioned timestamp.

See https://marc.info/?l=openbsd-tech&m=155044284526535 for details.
wip/unchecked-remove
Klemens Nanni 6 years ago committed by Oswald Buddenhagen
parent
commit
d61f462039
  1. 2
      src/drv_imap.c

2
src/drv_imap.c

@ -949,7 +949,7 @@ parse_date( const char *str )
struct tm datetime; struct tm datetime;
memset( &datetime, 0, sizeof(datetime) ); memset( &datetime, 0, sizeof(datetime) );
if (!(end = strptime( str, "%d-%b-%Y %H:%M:%S ", &datetime ))) if (!(end = strptime( str, "%e-%b-%Y %H:%M:%S ", &datetime )))
return -1; return -1;
if ((date = timegm( &datetime )) == -1) if ((date = timegm( &datetime )) == -1)
return -1; return -1;

Loading…
Cancel
Save