Bug #68787 [Opn->Nab]: Incorrect code
Edit report at https://bugs.php.net/bug.php?id=68787&edit=1
ID: 68787
Updated by: yohgaki@php.net
Reported by: bugreports at internot dot info
Summary: Incorrect code
-Status: Open
+Status: Not a bug
Type: Bug
Package: PHAR related
Operating System: Linux Ubuntu 14.04
PHP Version: master-Git-2015-01-10 (Git)
Block user comment: N
Private report: N
New Comment:
http://stackoverflow.com/questions/3110088/switch-statement-must-default-be-the-last-case
Although it may seem strange, this code is valid.
Previous Comments:
------------------------------------------------------------------------
[2015-01-10 13:23:44] bugreports at internot dot info
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 this bug report at https://bugs.php.net/bug.php?id=68787&edit=1
Thread (2 messages)