summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-04-02 01:08:24 +0200
committerNikita Popov <nikita.ppv@gmail.com>2017-04-02 01:08:24 +0200
commit32dcc1eef037da88ff483dd49a5a153096d702fc (patch)
treefa51cb356392555a6d9e5c4cc9c2cbdc35d7aff2
parentdfb4875850d70b52ebf3cd1e530d2dae7ffe6240 (diff)
parent670041b60ec25e822564d337bae96e82e8d9ac89 (diff)
downloadphp-git-32dcc1eef037da88ff483dd49a5a153096d702fc.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
-rw-r--r--NEWS4
-rw-r--r--ext/openssl/openssl.c23
-rw-r--r--ext/openssl/tests/bug74341.phpt52
-rw-r--r--php.ini-development2
-rw-r--r--php.ini-production2
5 files changed, 73 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 8c7afbcf0e..a655dd36e0 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,10 @@ PHP NEWS
- Intl:
. Fixed bug #65683 (Intl does not support DateTimeImmutable). (Ben Scholzen)
+- OpenSSL:
+ . Fixed bug #74341 (openssl_x509_parse fails to parse ASN.1 UTCTime without
+ seconds). (Moritz Fain)
+
13 Apr 2017, PHP 7.1.4
- Core:
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index c1b433eb93..556e377081 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -910,23 +910,26 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
char * strbuf;
char * thestr;
long gmadjust = 0;
+ size_t timestr_len;
if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME && ASN1_STRING_type(timestr) != V_ASN1_GENERALIZEDTIME) {
php_error_docref(NULL, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- if ((size_t)ASN1_STRING_length(timestr) != strlen((const char*)ASN1_STRING_data(timestr))) {
+ timestr_len = (size_t)ASN1_STRING_length(timestr);
+
+ if (timestr_len != strlen((const char*)ASN1_STRING_data(timestr))) {
php_error_docref(NULL, E_WARNING, "illegal length in timestamp");
return (time_t)-1;
}
- if (ASN1_STRING_length(timestr) < 13) {
+ if (timestr_len < 13 && timestr_len != 11) {
php_error_docref(NULL, E_WARNING, "unable to parse time string %s correctly", timestr->data);
return (time_t)-1;
}
- if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && ASN1_STRING_length(timestr) < 15) {
+ if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) {
php_error_docref(NULL, E_WARNING, "unable to parse time string %s correctly", timestr->data);
return (time_t)-1;
}
@@ -937,11 +940,15 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + ASN1_STRING_length(timestr) - 3;
+ thestr = strbuf + timestr_len - 3;
- thetime.tm_sec = atoi(thestr);
- *thestr = '\0';
- thestr -= 2;
+ if (timestr_len == 11) {
+ thetime.tm_sec = 0;
+ } else {
+ thetime.tm_sec = atoi(thestr);
+ *thestr = '\0';
+ thestr -= 2;
+ }
thetime.tm_min = atoi(thestr);
*thestr = '\0';
thestr -= 2;
@@ -978,7 +985,7 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
** the value of timezone - 3600 seconds. Otherwise, we need to overcorrect and
** set the adjustment to the main timezone + 3600 seconds.
*/
- gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone + 3600);
+ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone);
#endif
ret += gmadjust;
diff --git a/ext/openssl/tests/bug74341.phpt b/ext/openssl/tests/bug74341.phpt
new file mode 100644
index 0000000000..a3c78cfab0
--- /dev/null
+++ b/ext/openssl/tests/bug74341.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Bug #74341 (openssl_x509_parse fails to parse ASN.1 UTCTime without seconds)
+--SKIPIF--
+<?php if (!extension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gaGjIMZjHDgR/tE9FKFB66k8UTDzAwwEs38VV24zx6h
+lOzTF7xAUxmPUnNb2teatMf2Rmj0fs+d
+-----END CERTIFICATE-----
+';
+
+$parsed_cert = openssl_x509_parse($pem_cert);
+var_dump($parsed_cert['validFrom_time_t']);
+var_dump($parsed_cert['validTo_time_t']);
+?>
+--EXPECTF--
+int(1389052800)
+int(1459494000)
diff --git a/php.ini-development b/php.ini-development
index 3315cb3344..d8701951b1 100644
--- a/php.ini-development
+++ b/php.ini-development
@@ -1791,7 +1791,7 @@ ldap.max_links = -1
;opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
-; Only numbers between 200 and 100000 are allowed.
+; Only numbers between 200 and 1000000 are allowed.
;opcache.max_accelerated_files=10000
; The maximum percentage of "wasted" memory until a restart is scheduled.
diff --git a/php.ini-production b/php.ini-production
index 601e41c573..a8ac8825e7 100644
--- a/php.ini-production
+++ b/php.ini-production
@@ -1791,7 +1791,7 @@ ldap.max_links = -1
;opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
-; Only numbers between 200 and 100000 are allowed.
+; Only numbers between 200 and 1000000 are allowed.
;opcache.max_accelerated_files=10000
; The maximum percentage of "wasted" memory until a restart is scheduled.