Bug #68787 [NEW]: Incorrect code

From: Date: Sat, 10 Jan 2015 13:23:44 +0000
Subject: Bug #68787 [NEW]: Incorrect code
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189859@lists.php.net to get a copy of this message
From:             bugreports at internot dot info
Operating system: Linux Ubuntu 14.04
PHP version:      master-Git-2015-01-10 (Git)
Package:          PHAR related
Bug Type:         Bug
Bug description:Incorrect code

Description:
------------
Hi,

In /ext/phar/util.c:



1876                                return FAILURE;
1877                        }
1878#endif
1879                        *signature = (char *) sigbuf;
1880                        *signature_length = siglen;
1881                }
1882                break;
    
1883                default:
1884                        phar->sig_flags = PHAR_SIG_SHA1;
    

1885                case PHAR_SIG_SHA1: {
1886                        unsigned char digest[20];
1887                        PHP_SHA1_CTX  context;
1888
1889                        PHP_SHA1Init(&context);
1890
1891                        while ((sig_len = php_stream_read(fp,
(char*)buf, sizeof(buf))) > 0) {
1892                                PHP_SHA1Update(&context, buf,
sig_len);
1893                        }
1894
1895                        PHP_SHA1Final(digest, &context);
1896                        *signature = estrndup((char *) digest, 20);
1897                        *signature_length = 20;
1898                        break;
1899                }
1900                case PHAR_SIG_MD5: {
1901                        unsigned char digest[16];
1902                        PHP_MD5_CTX   context;
1903
1904                        PHP_MD5Init(&context);
1905
1906                        while ((sig_len = php_stream_read(fp,
(char*)buf, sizeof(buf))) > 0) {
1907                                PHP_MD5Update(&context, buf,
sig_len);
1908                        }
1909
1910                        PHP_MD5Final(digest, &context);
1911                        *signature = estrndup((char *) digest, 16);
1912                        *signature_length = 16;
1913                        break;
1914               



Multiple problems.

1. at L1882, 'break;' breaks out of the whole expression, not just the
case that L1881 closes.

2. case PHAR_SIG_SHA1 should be second last, and default should be the
last. That would make PHAR_SIG_MD5 the third last.




Thanks,


-- 
Edit bug report at https://bugs.php.net/bug.php?id=68787&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68787&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68787&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68787&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68787&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68787&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68787&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68787&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68787&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68787&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68787&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68787&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68787&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68787&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68787&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68787&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68787&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68787&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68787&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68787&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68787&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#189859) next »