|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-11-25 05:00 UTC] brian_bisaillon at rogers dot com
Description:
------------
./configure --prefix=/opt/php
--with-apxs2=/opt/apache/bin/apxs \
--with-mod_charset --disable-cgi --enable-magic-quotes
--with-openssl \
--with-libxml-dir=/usr/lib --with-zlib --enable-bcmath
--with-bz2 \
--enable-calendar --with-jpeg-dir=/usr/lib
--with-tiff-dir=/usr/lib \
--with-curl --with-curlwrappers --with-db4 --with-cdb
--with-inifile \
--with-flatfile --enable-dbase --enable-dbx --enable-dio
--with-fam \
--enable-filepro --enable-ftp --with-gd
--with-png-dir=/usr/lib \
--with-xpm-dir=/usr/lib --with-ttf
--with-freetype-dir=/usr/lib \
--with-gettext --with-gmp --with-kerberos --with-ldap
--with-ldap-sasl \
--enable-mbstring --with-mcrypt --with-mhash
--with-mysql=/opt/mysql \
--with-mysqli=/opt/mysql/bin/mysql_config --with-ncurses
--with-unixODBC \
--with-pgsql=/opt/postgresql --with-readline
--enable-shmop --with-snmp \
--enable-ucd-snmp-hack --enable-soap --enable-sockets \
--enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem
--enable-sysvshm \
--with-tidy=/usr --enable-wddx --with-xmlrpc --with-xsl
--enable-yp \
--enable-maintainer-zts --enable-memory-limit
--enable-zend-multibyte \
--with-tsrm-pthreads
Reproduce code:
---------------
$returnValue = @mcrypt_generic_init($this->encryptionDescriptor, $encryptionKey, $this->SetRandomIv());
if (0 == intval($returnValue) && -3 !== $returnValue && -4 !== $returnValue) {
throw new Exception("<h1>\n Initialization Failed\n</h1>\n<strong>Fatal:</strong> mcrypt_generic_init(): An unknown error occurred : phpwebtk.cryptography.Crypt.Exception <strong>");
} else if (-3 == $returnValue) {
throw new Exception("<h1>\n Initialization Failed\n</h1>\n<strong>Fatal:</strong> mcrypt_generic_init(): The key length was incorrect : phpwebtk.cryptography.Crypt.Exception <strong>");
} else if (-4 == $returnValue) {
throw new Exception("<h1>\n Initialization Failed\n</h1>\n<strong>Fatal:</strong> mcrypt_generic_init(): There was a memory allocation problem : phpwebtk.cryptography.Crypt.Exception <strong>");
} else {
$ciphertext = mcrypt_generic($this->encryptionDescriptor, $plaintext);
mcrypt_generic_deinit($this->encryptionDescriptor);
$this->CloseModule();
}
Expected result:
----------------
I expected the $returnValue to be a negative integer since
I gave a bogus $this->encryptionDescriptor and according
to the PHP manual, mcrypt_generic_init is supposed to
return a negative integer on error.
Actual result:
--------------
$returnValue was null despite the fact that
$this->encryptionDescriptor was invalid. It showed the
warning but I want to throw my own custom exception and
use the @mcrypt_generic_init() syntax to hide the default
warning. I cannot do that if a negative integer is not
being returned upon an error.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 00:00:01 2025 UTC |
There is no bug here, it simply returns false when an invalid encryption parameter is passed: derick@kossu:~$ php -r 'var_dump(mcrypt_generic_init("foo", "key", "1"));' Warning: mcrypt_generic_init(): supplied argument is not a valid MCrypt resource in Command line code on line 1 bool(false) The documentation is slightly wrong: The function returns a negative value on error, -3 when the key length was incorrect, -4 when there was a memory allocation problem and any other return value is an unknown error. It should state that returning bool(false) means that the encryption identifier is invalid.