Skip to content

Commit d8ed84e

Browse files
committed
Use zpp for accepting encryption mode string
Leaving the non-zpp usage for the mcrypt_{MODE} functions, as they're deprecated and I'm too lazy to update all their tests.
1 parent eb0eac7 commit d8ed84e

File tree

3 files changed

+38
-50
lines changed

3 files changed

+38
-50
lines changed

ext/mcrypt/mcrypt.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,31 +1296,31 @@ static void php_mcrypt_do_crypt(char* cipher, const char *key, int key_len, cons
12961296
OFB crypt/decrypt data using key key with cipher cipher starting with iv */
12971297
PHP_FUNCTION(mcrypt_encrypt)
12981298
{
1299-
zval **mode;
1300-
char *cipher, *key, *data, *iv = NULL;
1301-
int cipher_len, key_len, data_len, iv_len = 0;
1299+
char *cipher, *key, *data, *mode, *iv = NULL;
1300+
int cipher_len, key_len, data_len, mode_len, iv_len = 0;
13021301

1303-
MCRYPT_GET_CRYPT_ARGS
1304-
1305-
convert_to_string_ex(mode);
1302+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss|s", &cipher, &cipher_len,
1303+
&key, &key_len, &data, &data_len, &mode, &mode_len, &iv, &iv_len) == FAILURE) {
1304+
return;
1305+
}
13061306

1307-
php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, Z_STRVAL_PP(mode), iv, iv_len, MCRYPT_ENCRYPT, return_value TSRMLS_CC);
1307+
php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, mode, iv, iv_len, MCRYPT_ENCRYPT, return_value TSRMLS_CC);
13081308
}
13091309
/* }}} */
13101310

13111311
/* {{{ proto string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
13121312
OFB crypt/decrypt data using key key with cipher cipher starting with iv */
13131313
PHP_FUNCTION(mcrypt_decrypt)
13141314
{
1315-
zval **mode;
1316-
char *cipher, *key, *data, *iv = NULL;
1317-
int cipher_len, key_len, data_len, iv_len = 0;
1315+
char *cipher, *key, *data, *mode, *iv = NULL;
1316+
int cipher_len, key_len, data_len, mode_len, iv_len = 0;
13181317

1319-
MCRYPT_GET_CRYPT_ARGS
1320-
1321-
convert_to_string_ex(mode);
1318+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss|s", &cipher, &cipher_len,
1319+
&key, &key_len, &data, &data_len, &mode, &mode_len, &iv, &iv_len) == FAILURE) {
1320+
return;
1321+
}
13221322

1323-
php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, Z_STRVAL_PP(mode), iv, iv_len, MCRYPT_DECRYPT, return_value TSRMLS_CC);
1323+
php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, mode, iv, iv_len, MCRYPT_DECRYPT, return_value TSRMLS_CC);
13241324
}
13251325
/* }}} */
13261326

ext/mcrypt/tests/mcrypt_decrypt_variation4.phpt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,20 @@ Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
160160
bool(false)
161161

162162
--empty array--
163-
Error: 8 - Array to string conversion, %s(%d)
164-
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
165-
bool(false)
163+
Error: 2 - mcrypt_decrypt() expects parameter 4 to be string, array given, %s(%d)
164+
NULL
166165

167166
--int indexed array--
168-
Error: 8 - Array to string conversion, %s(%d)
169-
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
170-
bool(false)
167+
Error: 2 - mcrypt_decrypt() expects parameter 4 to be string, array given, %s(%d)
168+
NULL
171169

172170
--associative array--
173-
Error: 8 - Array to string conversion, %s(%d)
174-
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
175-
bool(false)
171+
Error: 2 - mcrypt_decrypt() expects parameter 4 to be string, array given, %s(%d)
172+
NULL
176173

177174
--nested arrays--
178-
Error: 8 - Array to string conversion, %s(%d)
179-
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
180-
bool(false)
175+
Error: 2 - mcrypt_decrypt() expects parameter 4 to be string, array given, %s(%d)
176+
NULL
181177

182178
--uppercase NULL--
183179
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
@@ -216,10 +212,8 @@ Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
216212
bool(false)
217213

218214
--instance of classWithoutToString--
219-
Error: 4096 - Object of class classWithoutToString could not be converted to string, %s(%d)
220-
Error: 8 - Object of class classWithoutToString to string conversion, %s(%d)
221-
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
222-
bool(false)
215+
Error: 2 - mcrypt_decrypt() expects parameter 4 to be string, object given, %s(%d)
216+
NULL
223217

224218
--undefined var--
225219
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
@@ -230,6 +224,6 @@ Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
230224
bool(false)
231225

232226
--resource--
233-
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
234-
bool(false)
227+
Error: 2 - mcrypt_decrypt() expects parameter 4 to be string, resource given, %s(%d)
228+
NULL
235229
===DONE===

ext/mcrypt/tests/mcrypt_encrypt_variation4.phpt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,20 @@ Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
160160
bool(false)
161161

162162
--empty array--
163-
Error: 8 - Array to string conversion, %s(%d)
164-
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
165-
bool(false)
163+
Error: 2 - mcrypt_encrypt() expects parameter 4 to be string, array given, %s(%d)
164+
NULL
166165

167166
--int indexed array--
168-
Error: 8 - Array to string conversion, %s(%d)
169-
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
170-
bool(false)
167+
Error: 2 - mcrypt_encrypt() expects parameter 4 to be string, array given, %s(%d)
168+
NULL
171169

172170
--associative array--
173-
Error: 8 - Array to string conversion, %s(%d)
174-
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
175-
bool(false)
171+
Error: 2 - mcrypt_encrypt() expects parameter 4 to be string, array given, %s(%d)
172+
NULL
176173

177174
--nested arrays--
178-
Error: 8 - Array to string conversion, %s(%d)
179-
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
180-
bool(false)
175+
Error: 2 - mcrypt_encrypt() expects parameter 4 to be string, array given, %s(%d)
176+
NULL
181177

182178
--uppercase NULL--
183179
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
@@ -216,10 +212,8 @@ Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
216212
bool(false)
217213

218214
--instance of classWithoutToString--
219-
Error: 4096 - Object of class classWithoutToString could not be converted to string, %s(%d)
220-
Error: 8 - Object of class classWithoutToString to string conversion, %s(%d)
221-
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
222-
bool(false)
215+
Error: 2 - mcrypt_encrypt() expects parameter 4 to be string, object given, %s(%d)
216+
NULL
223217

224218
--undefined var--
225219
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
@@ -230,6 +224,6 @@ Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
230224
bool(false)
231225

232226
--resource--
233-
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
234-
bool(false)
227+
Error: 2 - mcrypt_encrypt() expects parameter 4 to be string, resource given, %s(%d)
228+
NULL
235229
===DONE===

0 commit comments

Comments
 (0)