Fix null pointer dereference in parse_date().

Passing a date in format "mm-dd-yy" where short forms are not allowed
would lead to a null pointer dereference here. This one fixes that.
Spotted by clang-analyzer.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2011-04-11 16:47:23 +02:00
parent 5fc6d92866
commit 3a4431e568

View File

@ -843,6 +843,8 @@ parse_date (char *date_string, enum datefmt datefmt, int *year, int *month,
return 0; return 0;
} }
if (slctd_date)
{
if (y > 0 && y < 100) if (y > 0 && y < 100)
{ {
/* convert "YY" format into "YYYY" */ /* convert "YY" format into "YYYY" */
@ -854,6 +856,7 @@ parse_date (char *date_string, enum datefmt datefmt, int *year, int *month,
y = slctd_date->yyyy; y = slctd_date->yyyy;
if (n < 1) m = slctd_date->mm; if (n < 1) m = slctd_date->mm;
} }
}
/* check if date is valid, take leap years into account */ /* check if date is valid, take leap years into account */
if (y < 1902 || y > 2037 || m < 1 || m > 12 || d < 1 || if (y < 1902 || y > 2037 || m < 1 || m > 12 || d < 1 ||