Skip to content

Commit 0142705

Browse files
committed
A couple more
1 parent 2698197 commit 0142705

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

ext/zip/php_zip.c

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ typedef struct {
335335
#endif
336336
} zip_options;
337337

338-
static int php_zip_parse_options(HashTable *options, zip_options *opts)
338+
static bool php_zip_parse_options(HashTable *options, zip_options *opts)
339339
/* {{{ */
340340
{
341341
zval *option;
@@ -349,25 +349,46 @@ static int php_zip_parse_options(HashTable *options, zip_options *opts)
349349
#endif
350350

351351
if ((option = zend_hash_str_find(options, "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
352-
opts->remove_all_path = zval_get_long(option);
352+
if (Z_TYPE_P(option) != IS_FALSE && Z_TYPE_P(option) != IS_TRUE) {
353+
zend_type_error("Option \"remove_all_path\" must be of type bool, %s given",
354+
zend_zval_type_name(option));
355+
return false;
356+
}
357+
opts->remove_all_path = Z_LVAL_P(option);
353358
}
354359

355360
if ((option = zend_hash_str_find(options, "comp_method", sizeof("comp_method") - 1)) != NULL) {
356-
opts->comp_method = zval_get_long(option);
361+
if (Z_TYPE_P(option) != IS_LONG) {
362+
zend_type_error("Option \"comp_method\" must be of type int, %s given",
363+
zend_zval_type_name(option));
364+
return false;
365+
}
366+
opts->comp_method = Z_LVAL_P(option);
357367

358368
if ((option = zend_hash_str_find(options, "comp_flags", sizeof("comp_flags") - 1)) != NULL) {
359-
opts->comp_flags = zval_get_long(option);
369+
if (Z_TYPE_P(option) != IS_LONG) {
370+
zend_type_error("Option \"comp_flags\" must be of type int, %s given",
371+
zend_zval_type_name(option));
372+
return false;
373+
}
374+
opts->comp_flags = Z_LVAL_P(option);
360375
}
361376
}
362377

363378
#ifdef HAVE_ENCRYPTION
364379
if ((option = zend_hash_str_find(options, "enc_method", sizeof("enc_method") - 1)) != NULL) {
365-
opts->enc_method = zval_get_long(option);
380+
if (Z_TYPE_P(option) != IS_LONG) {
381+
zend_type_error("Option \"enc_method\" must be of type int, %s given",
382+
zend_zval_type_name(option));
383+
return false;
384+
}
385+
opts->enc_method = Z_LVAL_P(option);
366386

367387
if ((option = zend_hash_str_find(options, "enc_password", sizeof("enc_password") - 1)) != NULL) {
368388
if (Z_TYPE_P(option) != IS_STRING) {
369-
php_error_docref(NULL, E_WARNING, "enc_password option expected to be a string");
370-
return -1;
389+
zend_type_error("Option \"enc_password\" must be of type string, %s given",
390+
zend_zval_type_name(option));
391+
return false;
371392
}
372393
opts->enc_password = Z_STRVAL_P(option);
373394
}
@@ -376,53 +397,54 @@ static int php_zip_parse_options(HashTable *options, zip_options *opts)
376397

377398
if ((option = zend_hash_str_find(options, "remove_path", sizeof("remove_path") - 1)) != NULL) {
378399
if (Z_TYPE_P(option) != IS_STRING) {
379-
php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string");
380-
return -1;
400+
zend_type_error("Option \"remove_path\" must be of type string, %s given",
401+
zend_zval_type_name(option));
402+
return false;
381403
}
382404

383-
if (Z_STRLEN_P(option) < 1) {
384-
php_error_docref(NULL, E_NOTICE, "Empty string given as remove_path option");
385-
return -1;
405+
if (Z_STRLEN_P(option) == 0) {
406+
zend_type_error("Option \"remove_path\" cannot be empty");
407+
return false;
386408
}
387409

388410
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
389-
php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %d, %zd given)",
390-
MAXPATHLEN - 1, Z_STRLEN_P(option));
391-
return -1;
411+
zend_type_error("Option \"remove_path\" must be less than %d bytes", MAXPATHLEN - 1);
412+
return false;
392413
}
393414
opts->remove_path_len = Z_STRLEN_P(option);
394415
opts->remove_path = Z_STRVAL_P(option);
395416
}
396417

397418
if ((option = zend_hash_str_find(options, "add_path", sizeof("add_path") - 1)) != NULL) {
398419
if (Z_TYPE_P(option) != IS_STRING) {
399-
php_error_docref(NULL, E_WARNING, "add_path option expected to be a string");
400-
return -1;
420+
zend_type_error("Option \"add_path\" must be of type string, %s given",
421+
zend_zval_type_name(option));
422+
return false;
401423
}
402424

403-
if (Z_STRLEN_P(option) < 1) {
404-
php_error_docref(NULL, E_NOTICE, "Empty string given as the add_path option");
405-
return -1;
425+
if (Z_STRLEN_P(option) == 0) {
426+
zend_type_error("Option \"add_path\" cannot be empty");
427+
return false;
406428
}
407429

408430
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
409-
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %d, %zd given)",
410-
MAXPATHLEN - 1, Z_STRLEN_P(option));
411-
return -1;
431+
zend_type_error("Option \"add_path\" must be less than %d bytes", MAXPATHLEN - 1);
432+
return false;
412433
}
413434
opts->add_path_len = Z_STRLEN_P(option);
414435
opts->add_path = Z_STRVAL_P(option);
415436
}
416437

417438
if ((option = zend_hash_str_find(options, "flags", sizeof("flags") - 1)) != NULL) {
418439
if (Z_TYPE_P(option) != IS_LONG) {
419-
php_error_docref(NULL, E_WARNING, "flags option expected to be a integer");
420-
return -1;
440+
zend_type_error("Option \"flags\" must be of type int, %s given",
441+
zend_zval_type_name(option));
442+
return false;
421443
}
422444
opts->flags = Z_LVAL_P(option);
423445
}
424446

425-
return 1;
447+
return true;
426448
}
427449
/* }}} */
428450

@@ -1683,8 +1705,8 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
16831705
zend_argument_value_error(1, "cannot be empty");
16841706
RETURN_THROWS();
16851707
}
1686-
if (options && zend_hash_num_elements(options) > 0 && (php_zip_parse_options(options, &opts) < 0)) {
1687-
RETURN_FALSE;
1708+
if (options && zend_hash_num_elements(options) > 0 && (php_zip_parse_options(options, &opts) == false)) {
1709+
RETURN_THROWS();
16881710
}
16891711

16901712
if (type == 1) {

0 commit comments

Comments
 (0)