#30891 [NEW]: mcrypt_generic_init() not returning negative integer on error
| From: | brian_bisaillon at rogers dot com | Date: | Thu, 25 Nov 2004 04:00:33 +0000 |
| Subject: | #30891 [NEW]: mcrypt_generic_init() not returning negative integer on error | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-69431@lists.php.net to get a copy of this message | ||
From: brian_bisaillon at rogers dot com
Operating system: SuSE Linux 9.1
PHP version: 5.0.2
PHP Bug Type: mcrypt related
Bug description: mcrypt_generic_init() not returning negative integer on error
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 bug report at http://bugs.php.net/?id=30891&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30891&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30891&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30891&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30891&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30891&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30891&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30891&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30891&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30891&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30891&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30891&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30891&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30891&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30891&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30891&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30891&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30891&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30891&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30891&r=mysqlcfg