]> granicus.if.org Git - php/commitdiff
- There was nothing wrong here, bug report #37595 is bogus.
authorDerick Rethans <derick@php.net>
Wed, 31 May 2006 20:09:07 +0000 (20:09 +0000)
committerDerick Rethans <derick@php.net>
Wed, 31 May 2006 20:09:07 +0000 (20:09 +0000)
- Added a new test case to demonstrate a longer plain text.

NEWS
ext/mcrypt/mcrypt.c
ext/mcrypt/tests/blowfish.phpt
ext/mcrypt/tests/bug37595.phpt

diff --git a/NEWS b/NEWS
index a9c2e616ec2f796b0bfdad6e8b6f96a6cf1ae2ed..db78febd82747a51657ed91cf0197c1673030268 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -55,8 +55,6 @@ PHP                                                                        NEWS
 - Fixed bug #37616 (DATE_RFC822 does not product RFC 822 dates).
   (Hannes Magnusson, Derick)
 - Fixed bug #37614 (Class name lowercased in error message). (Johannes)
-- Fixed bug #37595 (mcrypt_generic calculates data length in wrong way). 
-  (Tony)
 - Fixed bug #37587 (var without attribute causes segfault). (Marcus)
 - Fixed bug #37586 (Bumped minimum PCRE version to 6.6, needed for recursion
   limit support). (Ilia)
index a76ae2ee58a23bc7598baa1cc4115951d1da821a..da4ce8ef79e8dd5f7b112ade1e06f0b0a37c50e4 100644 (file)
@@ -492,11 +492,15 @@ PHP_FUNCTION(mcrypt_generic)
        ZEND_FETCH_RESOURCE(pm, php_mcrypt *, mcryptind, -1, "MCrypt", le_mcrypt);
        PHP_MCRYPT_INIT_CHECK
        convert_to_string_ex(data);
+       if (Z_STRLEN_PP(data) == 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "An empty string was passed");
+               RETURN_FALSE
+       }
 
        /* Check blocksize */
        if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
                block_size = mcrypt_enc_get_block_size(pm->td);
-               data_size = ((Z_STRLEN_PP(data) / block_size) + 1) * block_size;
+               data_size = (((Z_STRLEN_PP(data) - 1) / block_size) + 1) * block_size;
                data_s = emalloc(data_size + 1);
                memset(data_s, 0, data_size);
                memcpy(data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data));
@@ -533,6 +537,10 @@ PHP_FUNCTION(mdecrypt_generic)
        ZEND_FETCH_RESOURCE(pm, php_mcrypt * , mcryptind, -1, "MCrypt", le_mcrypt);
        PHP_MCRYPT_INIT_CHECK
        convert_to_string_ex(data);
+       if (Z_STRLEN_PP(data) == 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "An empty string was passed");
+               RETURN_FALSE
+       }
 
        /* Check blocksize */
        if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
index dc51da65b37e7f1a0ede5ce5e0b86822f6aaabbe..ce258d3e13a9c0cb20812530187c421b31638f20 100644 (file)
@@ -36,7 +36,19 @@ foreach($vectors as $data) {
             ($crypt==$guess ? "OK" : "BAD")
         );  
     }   
-}   
+}
+
+// Longer test case from http://www.schneier.com/code/vectors.txt
+$td = mcrypt_module_open ("blowfish", "", MCRYPT_MODE_CBC, "");
+
+$key = hex2bin( "0123456789ABCDEFF0E1D2C3B4A59687" );
+$iv = hex2bin( "FEDCBA9876543210" );
+$plain = hex2bin( "37363534333231204E6F77206973207468652074696D6520666F722000" );
+
+mcrypt_generic_init( $td, $key, $iv );
+$guess = bin2hex( mcrypt_generic( $td, $plain ) );
+
+echo "\n", $guess, "\n";
 ?>
 --EXPECT--
 key               plain             crypt             guess             stat
@@ -73,3 +85,5 @@ E0FEE0FEF1FEF1FE  0123456789ABCDEF  c39e072d9fac631d  c39e072d9fac631d  OK
 FFFFFFFFFFFFFFFF  0000000000000000  f21e9a77b71c49bc  f21e9a77b71c49bc  OK
 0123456789ABCDEF  0000000000000000  245946885754369a  245946885754369a  OK
 FEDCBA9876543210  FFFFFFFFFFFFFFFF  6b5c5a9c5d9e0a5a  6b5c5a9c5d9e0a5a  OK
+
+6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc
index a74b8cfaa80aa2e98687d91be101e3492b948491..3499612bf46fcdff0d2b300e1edd1e0b98ddd17a 100644 (file)
Binary files a/ext/mcrypt/tests/bug37595.phpt and b/ext/mcrypt/tests/bug37595.phpt differ