Commit 09d7a573 authored by Frederick Zhang's avatar Frederick Zhang

fix key and val handling for nul char

parent e661ff4d
Pipeline #333 passed with stage
in 39 seconds
......@@ -256,23 +256,23 @@ zval * bdict::to_array(const bool include_meta) const {
zval *value = zend_hash_get_current_data(_data);
std::string class_name = zend_container::bnode_object_get_class_name(value);
char *str_index = (char *)emalloc(ZSTR_LEN(_str_index) + 1);
strcpy(str_index, ZSTR_VAL(_str_index));
memcpy(str_index, ZSTR_VAL(_str_index), ZSTR_LEN(_str_index));
if (class_name == "bdict") {
bdict_object *bnode = zend_container::bdict_fetch_object(Z_OBJ_P(value));
zval *subarray = bnode->bdict_data->to_array(include_meta);
add_assoc_zval(zv, str_index, subarray);
add_assoc_zval_ex(zv, str_index, ZSTR_LEN(_str_index), subarray);
} else if (class_name == "blist") {
blist_object *bnode = zend_container::blist_fetch_object(Z_OBJ_P(value));
zval *subarray = bnode->blist_data->to_array(include_meta);
add_assoc_zval(zv, str_index, subarray);
add_assoc_zval_ex(zv, str_index, ZSTR_LEN(_str_index), subarray);
} else if (class_name == "bstr") {
bstr_object *bnode = zend_container::bstr_fetch_object(Z_OBJ_P(value));
zval *subarray = bnode->bstr_data->to_array(include_meta);
add_assoc_zval(zv, str_index, subarray);
add_assoc_zval_ex(zv, str_index, ZSTR_LEN(_str_index), subarray);
} else if (class_name == "bint") {
bint_object *bnode = zend_container::bint_fetch_object(Z_OBJ_P(value));
zval *subarray = bnode->bint_data->to_array(include_meta);
add_assoc_zval(zv, str_index, subarray);
add_assoc_zval_ex(zv, str_index, ZSTR_LEN(_str_index), subarray);
}
efree(str_index);
}
......
......@@ -54,7 +54,7 @@ zval * bstr::to_array(const bool include_meta) const {
char *_length = estrdup("_length");
char *_data = estrdup("_data");
char *_data_data = (char*)emalloc(_value.length() + 1);
strcpy(_data_data, _value.c_str());
memcpy(_data_data, _value.c_str(), _value.length());
add_assoc_string(zv, _type, _type_data);
add_assoc_long(zv, _length, length());
add_assoc_stringl(zv, _data, _data_data, _value.length());
......@@ -65,7 +65,7 @@ zval * bstr::to_array(const bool include_meta) const {
efree(_data_data);
} else {
char *_data_data = (char *)emalloc(_value.length() + 1);
strcpy(_data_data, _value.c_str());
memcpy(_data_data, _value.c_str(), _value.length());
ZVAL_STRINGL(zv, _data_data, _value.length());
efree(_data_data);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment