ID: 30891 User updated by: brian_bisaillon at rogers dot com Reported By: brian_bisaillon at rogers dot com Status: Open Bug Type: mcrypt related Operating System: SuSE Linux 9.1 PHP Version: 5.0.2 New Comment:
My error checking for -3 worked so it's setting a negative integer when I supply an invalid $encryptionKey. However, the problem is with returning negative integers for "unknown errors" such as an invalid MCrypt resource. In those situations, it doesn't return a negative integer like it's supposed to. Previous Comments: ------------------------------------------------------------------------ [2004-11-25 05:00:28] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30891&edit=1