diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index f6ed67b805b67..a8b5ec82534ba 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -717,7 +717,7 @@ static time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */ return (time_t)-1; } - if (timestr_len < 13 && timestr_len != 11) { + if (timestr_len < 13) { php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data); return (time_t)-1; } @@ -735,13 +735,9 @@ static time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */ thestr = strbuf + timestr_len - 3; - if (timestr_len == 11) { - thetime.tm_sec = 0; - } else { - thetime.tm_sec = atoi(thestr); - *thestr = '\0'; - thestr -= 2; - } + thetime.tm_sec = atoi(thestr); + *thestr = '\0'; + thestr -= 2; thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; diff --git a/ext/openssl/tests/gh13343.phpt b/ext/openssl/tests/gh13343.phpt new file mode 100644 index 0000000000000..2f6590e04bb95 --- /dev/null +++ b/ext/openssl/tests/gh13343.phpt @@ -0,0 +1,56 @@ +--TEST-- +GH-13343: openssl_x509_parse should not allow omitted seconds in UTCTimes +--EXTENSIONS-- +openssl +--SKIPIF-- += 0x30300000) die('skip For OpenSSL < 3.3'); +?> +--FILE-- + +--EXPECTF-- + +Warning: openssl_x509_parse(): Unable to parse time string 1401070000Z correctly in %s on line %d +int(-1) diff --git a/ext/openssl/tests/bug74341.phpt b/ext/openssl/tests/gh13343_openssl33.phpt similarity index 90% rename from ext/openssl/tests/bug74341.phpt rename to ext/openssl/tests/gh13343_openssl33.phpt index 27269f473bfbb..2060708be06c1 100644 --- a/ext/openssl/tests/bug74341.phpt +++ b/ext/openssl/tests/gh13343_openssl33.phpt @@ -1,7 +1,11 @@ --TEST-- -Bug #74341 (openssl_x509_parse fails to parse ASN.1 UTCTime without seconds) +GH-13343: openssl_x509_parse should not allow omitted seconds in UTCTimes for OpenSSL 3.3+ --EXTENSIONS-- openssl +--SKIPIF-- += 3.3'); +?> --FILE-- --EXPECT-- -int(1389052800) -int(1459494000) +bool(false)