Skip to content

Commit 87e9c64

Browse files
committed
ext/standard/proc_open.c: Minor refactorings
Add const modifier Use unsigned types when the source type is unsigned
1 parent 07b61c1 commit 87e9c64

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

ext/standard/proc_open.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ typedef struct _descriptorspec_item {
506506
int mode_flags; /* mode for opening FDs: r/o, r/w, binary (on Win32), etc */
507507
} descriptorspec_item;
508508

509-
static zend_string *get_valid_arg_string(zval *zv, int elem_num) {
509+
static zend_string *get_valid_arg_string(zval *zv, uint32_t elem_num) {
510510
zend_string *str = zval_get_string(zv);
511511
if (!str) {
512512
return NULL;
@@ -518,7 +518,7 @@ static zend_string *get_valid_arg_string(zval *zv, int elem_num) {
518518
return NULL;
519519
}
520520

521-
if (strlen(ZSTR_VAL(str)) != ZSTR_LEN(str)) {
521+
if (zend_str_has_nul_byte(str)) {
522522
zend_value_error("Command array element %d contains a null byte", elem_num);
523523
zend_string_release(str);
524524
return NULL;
@@ -630,7 +630,7 @@ static zend_string *create_win_command_from_args(HashTable *args)
630630
zval *arg_zv;
631631
bool is_prog_name = true;
632632
bool is_cmd_execution = false;
633-
int elem_num = 0;
633+
uint32_t elem_num = 0;
634634

635635
ZEND_HASH_FOREACH_VAL(args, arg_zv) {
636636
zend_string *arg_str = get_valid_arg_string(arg_zv, ++elem_num);
@@ -778,11 +778,11 @@ static zend_result convert_command_to_use_shell(wchar_t **cmdw, size_t cmdw_len)
778778

779779
#ifndef PHP_WIN32
780780
/* Convert command parameter array passed as first argument to `proc_open` into command string */
781-
static zend_string* get_command_from_array(HashTable *array, char ***argv, int num_elems)
781+
static zend_string* get_command_from_array(const HashTable *array, char ***argv, uint32_t num_elems)
782782
{
783783
zval *arg_zv;
784784
zend_string *command = NULL;
785-
int i = 0;
785+
uint32_t i = 0;
786786

787787
*argv = safe_emalloc(sizeof(char *), num_elems + 1, 0);
788788

@@ -810,16 +810,16 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n
810810
}
811811
#endif
812812

813-
static descriptorspec_item* alloc_descriptor_array(HashTable *descriptorspec)
813+
static descriptorspec_item* alloc_descriptor_array(const HashTable *descriptorspec)
814814
{
815815
uint32_t ndescriptors = zend_hash_num_elements(descriptorspec);
816816
return ecalloc(ndescriptors, sizeof(descriptorspec_item));
817817
}
818818

819-
static zend_string* get_string_parameter(zval *array, int index, char *param_name)
819+
static zend_string* get_string_parameter(const HashTable *ht, unsigned int index, const char *param_name)
820820
{
821821
zval *array_item;
822-
if ((array_item = zend_hash_index_find(Z_ARRVAL_P(array), index)) == NULL) {
822+
if ((array_item = zend_hash_index_find(ht, index)) == NULL) {
823823
zend_value_error("Missing %s", param_name);
824824
return NULL;
825825
}
@@ -1030,9 +1030,9 @@ static zend_result redirect_proc_descriptor(descriptorspec_item *desc, int targe
10301030
}
10311031

10321032
/* Process one item from `$descriptorspec` argument to `proc_open` */
1033-
static zend_result set_proc_descriptor_from_array(zval *descitem, descriptorspec_item *descriptors,
1033+
static zend_result set_proc_descriptor_from_array(const HashTable *ht, descriptorspec_item *descriptors,
10341034
int ndesc, int nindex, int *pty_master_fd, int *pty_slave_fd) {
1035-
zend_string *ztype = get_string_parameter(descitem, 0, "handle qualifier");
1035+
zend_string *ztype = get_string_parameter(ht, 0, "handle qualifier");
10361036
if (!ztype) {
10371037
return FAILURE;
10381038
}
@@ -1042,7 +1042,7 @@ static zend_result set_proc_descriptor_from_array(zval *descitem, descriptorspec
10421042

10431043
if (zend_string_equals_literal(ztype, "pipe")) {
10441044
/* Set descriptor to pipe */
1045-
zmode = get_string_parameter(descitem, 1, "mode parameter for 'pipe'");
1045+
zmode = get_string_parameter(ht, 1, "mode parameter for 'pipe'");
10461046
if (zmode == NULL) {
10471047
goto finish;
10481048
}
@@ -1052,16 +1052,16 @@ static zend_result set_proc_descriptor_from_array(zval *descitem, descriptorspec
10521052
retval = set_proc_descriptor_to_socket(&descriptors[ndesc]);
10531053
} else if (zend_string_equals(ztype, ZSTR_KNOWN(ZEND_STR_FILE))) {
10541054
/* Set descriptor to file */
1055-
if ((zfile = get_string_parameter(descitem, 1, "file name parameter for 'file'")) == NULL) {
1055+
if ((zfile = get_string_parameter(ht, 1, "file name parameter for 'file'")) == NULL) {
10561056
goto finish;
10571057
}
1058-
if ((zmode = get_string_parameter(descitem, 2, "mode parameter for 'file'")) == NULL) {
1058+
if ((zmode = get_string_parameter(ht, 2, "mode parameter for 'file'")) == NULL) {
10591059
goto finish;
10601060
}
10611061
retval = set_proc_descriptor_to_file(&descriptors[ndesc], zfile, zmode);
10621062
} else if (zend_string_equals_literal(ztype, "redirect")) {
10631063
/* Redirect descriptor to whatever another descriptor is set to */
1064-
zval *ztarget = zend_hash_index_find_deref(Z_ARRVAL_P(descitem), 1);
1064+
zval *ztarget = zend_hash_index_find_deref(ht, 1);
10651065
if (!ztarget) {
10661066
zend_value_error("Missing redirection target");
10671067
goto finish;
@@ -1302,7 +1302,7 @@ PHP_FUNCTION(proc_open)
13021302
goto exit_fail;
13031303
}
13041304
} else if (Z_TYPE_P(descitem) == IS_ARRAY) {
1305-
if (set_proc_descriptor_from_array(descitem, descriptors, ndesc, (int)nindex,
1305+
if (set_proc_descriptor_from_array(Z_ARRVAL_P(descitem), descriptors, ndesc, (int)nindex,
13061306
&pty_master_fd, &pty_slave_fd) == FAILURE) {
13071307
goto exit_fail;
13081308
}

0 commit comments

Comments
 (0)