@@ -1645,7 +1645,7 @@ PHP_FUNCTION(sodium_crypto_stream)
1645
1645
return ;
1646
1646
}
1647
1647
if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX ) {
1648
- zend_throw_exception (sodium_exception_ce , "invalid length" , 0 );
1648
+ zend_throw_exception (sodium_exception_ce , "ciphertext length must be greater than 0 " , 0 );
1649
1649
return ;
1650
1650
}
1651
1651
if (nonce_len != crypto_stream_NONCEBYTES ) {
@@ -1727,9 +1727,16 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
1727
1727
sodium_remove_param_values_from_backtrace (EG (exception ));
1728
1728
return ;
1729
1729
}
1730
- if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL ||
1731
- opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX ) {
1732
- zend_throw_exception (sodium_exception_ce , "invalid parameters" , 0 );
1730
+ if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL ) {
1731
+ zend_throw_exception (sodium_exception_ce , "hash length must be greater than 0" , 0 );
1732
+ return ;
1733
+ }
1734
+ if (opslimit <= 0 ) {
1735
+ zend_throw_exception (sodium_exception_ce , "ops limit must be greater than 0" , 0 );
1736
+ return ;
1737
+ }
1738
+ if (memlimit <= 0 || memlimit > SIZE_MAX ) {
1739
+ zend_throw_exception (sodium_exception_ce , "memory limit must be greater than 0" , 0 );
1733
1740
return ;
1734
1741
}
1735
1742
if (passwd_len <= 0 ) {
@@ -1777,8 +1784,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
1777
1784
sodium_remove_param_values_from_backtrace (EG (exception ));
1778
1785
return ;
1779
1786
}
1780
- if (opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX ) {
1781
- zend_throw_exception (sodium_exception_ce , "invalid parameters" , 0 );
1787
+ if (opslimit <= 0 ) {
1788
+ zend_throw_exception (sodium_exception_ce , "ops limit must be greater than 0" , 0 );
1789
+ return ;
1790
+ }
1791
+ if (memlimit <= 0 || memlimit > SIZE_MAX ) {
1792
+ zend_throw_exception (sodium_exception_ce , "memory limit must be greater than 0" , 0 );
1782
1793
return ;
1783
1794
}
1784
1795
if (passwd_len <= 0 ) {
@@ -1856,10 +1867,20 @@ PHP_FUNCTION(sodium_crypto_pwhash)
1856
1867
sodium_remove_param_values_from_backtrace (EG (exception ));
1857
1868
return ;
1858
1869
}
1859
- if (hash_len <= 0 || hash_len >= 0xffffffff ||
1860
- passwd_len >= 0xffffffff ||
1861
- opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX ) {
1862
- zend_throw_exception (sodium_exception_ce , "invalid parameters" , 0 );
1870
+ if (hash_len <= 0 || hash_len >= 0xffffffff ) {
1871
+ zend_throw_exception (sodium_exception_ce , "hash length must be greater than 0" , 0 );
1872
+ return ;
1873
+ }
1874
+ if (passwd_len >= 0xffffffff ) {
1875
+ zend_throw_exception (sodium_exception_ce , "unsupported password length" , 0 );
1876
+ return ;
1877
+ }
1878
+ if (opslimit <= 0 ) {
1879
+ zend_throw_exception (sodium_exception_ce , "ops limit must be greater than 0" , 0 );
1880
+ return ;
1881
+ }
1882
+ if (memlimit <= 0 || memlimit > SIZE_MAX ) {
1883
+ zend_throw_exception (sodium_exception_ce , "memory limit must be greater than 0" , 0 );
1863
1884
return ;
1864
1885
}
1865
1886
if (alg != crypto_pwhash_ALG_ARGON2I13
@@ -1914,9 +1935,16 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
1914
1935
sodium_remove_param_values_from_backtrace (EG (exception ));
1915
1936
return ;
1916
1937
}
1917
- if (opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX ||
1918
- passwd_len >= 0xffffffff ) {
1919
- zend_throw_exception (sodium_exception_ce , "invalid parameters" , 0 );
1938
+ if (opslimit <= 0 ) {
1939
+ zend_throw_exception (sodium_exception_ce , "ops limit must be greater than 0" , 0 );
1940
+ return ;
1941
+ }
1942
+ if (memlimit <= 0 || memlimit > SIZE_MAX ) {
1943
+ zend_throw_exception (sodium_exception_ce , "memory limit must be greater than 0" , 0 );
1944
+ return ;
1945
+ }
1946
+ if (passwd_len >= 0xffffffff ) {
1947
+ zend_throw_exception (sodium_exception_ce , "unsupported password length" , 0 );
1920
1948
return ;
1921
1949
}
1922
1950
if (passwd_len <= 0 ) {
0 commit comments