diff --git a/lib/ftp.c b/lib/ftp.c index a799c53279..d93d2d9ff4 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -2489,24 +2489,27 @@ static CURLcode ftp_state_port_resp(struct Curl_easy *data, return result; } -static int twodigit(const char *p) +/* return TRUE on error, FALSE on success */ +static bool twodigit(const char *p, int *val) { - return ((p[0] - '0') * 10) + (p[1] - '0'); + if(!ISDIGIT(p[0]) || !ISDIGIT(p[1])) + return TRUE; + /* curlx_hexval() works fine here since we make sure it is decimal above */ + *val = (curlx_hexval(p[0]) * 10) + curlx_hexval(p[1]); + return FALSE; } static bool ftp_213_date(const char *p, int *year, int *month, int *day, int *hour, int *minute, int *second) { - size_t len = strlen(p); - if(len < 14) + int century; + if((strlen(p) < 14) || twodigit(&p[0], ¢ury) || twodigit(&p[2], year) || + twodigit(&p[4], month) || twodigit(&p[6], day) || + twodigit(&p[8], hour) || twodigit(&p[10], minute) || + twodigit(&p[12], second)) return FALSE; - *year = (twodigit(&p[0]) * 100) + twodigit(&p[2]); - *month = twodigit(&p[4]); - *day = twodigit(&p[6]); - *hour = twodigit(&p[8]); - *minute = twodigit(&p[10]); - *second = twodigit(&p[12]); + *year += century * 100; if((*month > 12) || (*day > 31) || (*hour > 23) || (*minute > 59) || (*second > 60)) return FALSE; diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 34eb547d9c..f8d8548265 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -226,7 +226,7 @@ test1666 test1667 \ \ test1670 test1671 \ \ -test1680 test1681 test1682 test1683 \ +test1680 test1681 test1682 test1683 test1684 \ \ test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 \ test1708 test1709 test1710 test1711 test1712 test1713 \ diff --git a/tests/data/test1684 b/tests/data/test1684 new file mode 100644 index 0000000000..3de6c4d611 --- /dev/null +++ b/tests/data/test1684 @@ -0,0 +1,46 @@ + + + + +FTP +MDTM + + + + + +a joke + + +213 2003040a102659 + + + +# Client-side + + +ftp + + +FTP with malformed MDTM response + + +ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -z "apr 1 2025 08:00:00" + + + +# Verify data after the test has been "shot" + + +USER anonymous +PASS ftp@example.com +PWD +MDTM %TESTNUMBER +EPSV +TYPE I +SIZE %TESTNUMBER +RETR %TESTNUMBER +QUIT + + +