]> granicus.if.org Git - php/commitdiff
Fix outlen for openssl function
authorStanislav Malyshev <stas@php.net>
Thu, 13 Oct 2016 06:19:07 +0000 (23:19 -0700)
committerStanislav Malyshev <stas@php.net>
Thu, 13 Oct 2016 06:19:07 +0000 (23:19 -0700)
Even though datalen can't be over int, outlen can.

ext/openssl/openssl.c

index 648b110d619b474a0aed856380d408a6425d161b..6bf1d6b25f20530f9d91ea17ca9123d86abafb4a 100644 (file)
@@ -5303,7 +5303,8 @@ PHP_FUNCTION(openssl_encrypt)
        size_t data_len, method_len, password_len, iv_len = 0, max_iv_len;
        const EVP_CIPHER *cipher_type;
        EVP_CIPHER_CTX cipher_ctx;
-       int i=0, outlen, keylen;
+       int i=0, keylen;
+       size_t outlen;
        zend_string *outbuf;
        unsigned char *key;
        zend_bool free_iv;
@@ -5334,7 +5335,7 @@ PHP_FUNCTION(openssl_encrypt)
        }
        free_iv = php_openssl_validate_iv(&iv, &iv_len, max_iv_len);
 
-       outlen = (int)data_len + EVP_CIPHER_block_size(cipher_type);
+       outlen = data_len + EVP_CIPHER_block_size(cipher_type);
        outbuf = zend_string_alloc(outlen, 0);
 
        EVP_EncryptInit(&cipher_ctx, cipher_type, NULL, NULL);
@@ -5386,7 +5387,8 @@ PHP_FUNCTION(openssl_decrypt)
        size_t data_len, method_len, password_len, iv_len = 0;
        const EVP_CIPHER *cipher_type;
        EVP_CIPHER_CTX cipher_ctx;
-       int i, outlen, keylen;
+       int i, keylen;
+       size_t outlen;
        zend_string *outbuf;
        unsigned char *key;
        zend_string *base64_str = NULL;
@@ -5410,7 +5412,7 @@ PHP_FUNCTION(openssl_decrypt)
        }
 
        if (!(options & OPENSSL_RAW_DATA)) {
-               base64_str = php_base64_decode((unsigned char*)data, (int)data_len);
+               base64_str = php_base64_decode((unsigned char*)data, data_len);
                if (!base64_str) {
                        php_error_docref(NULL, E_WARNING, "Failed to base64 decode the input");
                        RETURN_FALSE;
@@ -5430,7 +5432,7 @@ PHP_FUNCTION(openssl_decrypt)
 
        free_iv = php_openssl_validate_iv(&iv, &iv_len, EVP_CIPHER_iv_length(cipher_type));
 
-       outlen = (int)data_len + EVP_CIPHER_block_size(cipher_type);
+       outlen = data_len + EVP_CIPHER_block_size(cipher_type);
        outbuf = zend_string_alloc(outlen, 0);
 
        EVP_DecryptInit(&cipher_ctx, cipher_type, NULL, NULL);