]> granicus.if.org Git - php/commitdiff
Fixed bug #71475: openssl_seal() uninitialized memory usage
authorStanislav Malyshev <stas@php.net>
Mon, 1 Feb 2016 04:18:46 +0000 (20:18 -0800)
committerStanislav Malyshev <stas@php.net>
Mon, 1 Feb 2016 04:18:46 +0000 (20:18 -0800)
ext/openssl/openssl.c
ext/openssl/tests/bug71475.phpt [new file with mode: 0644]

index a8ecbb232799f9b9751fdaacc51e1fcfc7578641..75c44a391884807769c4bce63fce8688d77aa3c6 100644 (file)
@@ -4938,6 +4938,7 @@ PHP_FUNCTION(openssl_seal)
        memset(eks, 0, sizeof(*eks) * nkeys);
        key_resources = safe_emalloc(nkeys, sizeof(zend_resource*), 0);
        memset(key_resources, 0, sizeof(zend_resource*) * nkeys);
+       memset(pkeys, 0, sizeof(*pkeys) * nkeys);
 
        /* get the public keys we are using to seal this data */
        i = 0;
@@ -4999,7 +5000,7 @@ PHP_FUNCTION(openssl_seal)
 
 clean_exit:
        for (i=0; i<nkeys; i++) {
-               if (key_resources[i] == NULL) {
+               if (key_resources[i] == NULL && pkeys[i] != NULL) {
                        EVP_PKEY_free(pkeys[i]);
                }
                if (eks[i]) {
diff --git a/ext/openssl/tests/bug71475.phpt b/ext/openssl/tests/bug71475.phpt
new file mode 100644 (file)
index 0000000..680753d
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #71475: openssl_seal() uninitialized memory usage
+--SKIPIF--
+<?php 
+if (!extension_loaded("openssl")) die("skip openssl not loaded");
+?>
+--FILE--
+<?php
+$_ = str_repeat("A", 512);
+openssl_seal($_, $_, $_, array_fill(0,64,0));
+?>
+DONE
+--EXPECTF--
+
+Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s/bug71475.php on line %d
+DONE
\ No newline at end of file