Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/intl/calendar/gregoriancalendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endif

#include "../intl_cppshims.h"
#include <memory>

#include <unicode/locid.h>
#include <unicode/calendar.h>
Expand Down
1 change: 1 addition & 0 deletions ext/intl/dateformat/dateformat_format_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#include "../intl_cppshims.h"
#include <memory>

#include <unicode/calendar.h>
#include <unicode/gregocal.h>
Expand Down
1 change: 1 addition & 0 deletions ext/intl/timezone/timezone_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#endif

#include "../intl_cppshims.h"
#include <memory>

#include <unicode/timezone.h>
#include <unicode/calendar.h>
Expand Down
46 changes: 15 additions & 31 deletions ext/json/json_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ static zend_always_inline bool php_json_check_stack_limit(void)
#endif
}

static int php_json_determine_array_type(zval *val) /* {{{ */
{
zend_array *myht = Z_ARRVAL_P(val);

if (myht) {
return zend_array_is_list(myht) ? PHP_JSON_OUTPUT_ARRAY : PHP_JSON_OUTPUT_OBJECT;
}

return PHP_JSON_OUTPUT_ARRAY;
}
/* }}} */

/* {{{ Pretty printing support functions */

static inline void php_json_pretty_print_char(smart_str *buf, int options, char c) /* {{{ */
Expand All @@ -63,12 +51,10 @@ static inline void php_json_pretty_print_char(smart_str *buf, int options, char
}
/* }}} */

static inline void php_json_pretty_print_indent(smart_str *buf, int options, php_json_encoder *encoder) /* {{{ */
static inline void php_json_pretty_print_indent(smart_str *buf, int options, const php_json_encoder *encoder) /* {{{ */
{
int i;

if (options & PHP_JSON_PRETTY_PRINT) {
for (i = 0; i < encoder->depth; ++i) {
for (int i = 0; i < encoder->depth; ++i) {
smart_str_appendl(buf, " ", 4);
}
}
Expand Down Expand Up @@ -122,7 +108,8 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)

static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
{
int r, need_comma = 0;
bool encode_as_object = options & PHP_JSON_FORCE_OBJECT;
bool need_comma = false;
HashTable *myht, *prop_ht;
zend_refcounted *recursion_rc;

Expand All @@ -138,17 +125,15 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
myht = Z_ARRVAL_P(val);
recursion_rc = (zend_refcounted *)myht;
prop_ht = NULL;
r = (options & PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT : php_json_determine_array_type(val);
encode_as_object = encode_as_object || !zend_array_is_list(myht);
} else if (Z_OBJ_P(val)->properties == NULL
&& Z_OBJ_HT_P(val)->get_properties_for == NULL
&& Z_OBJ_HT_P(val)->get_properties == zend_std_get_properties
&& Z_OBJ_P(val)->ce->num_hooked_props == 0
&& !zend_object_is_lazy(Z_OBJ_P(val))) {
/* Optimized version without rebuilding properties HashTable */
zend_object *obj = Z_OBJ_P(val);
zend_class_entry *ce = obj->ce;
zend_property_info *prop_info;
zval *prop;
const zend_class_entry *ce = obj->ce;

if (GC_IS_RECURSIVE(obj)) {
encoder->error_code = PHP_JSON_ERROR_RECURSION;
Expand All @@ -163,15 +148,15 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
++encoder->depth;

for (int i = 0; i < ce->default_properties_count; i++) {
prop_info = ce->properties_info_table[i];
zend_property_info *prop_info = ce->properties_info_table[i];
if (!prop_info) {
continue;
}
if (ZSTR_VAL(prop_info->name)[0] == '\0' && ZSTR_LEN(prop_info->name) > 0) {
/* Skip protected and private members. */
continue;
}
prop = OBJ_PROP(obj, prop_info->offset);
zval *prop = OBJ_PROP(obj, prop_info->offset);
if (Z_TYPE_P(prop) == IS_UNDEF) {
continue;
}
Expand Down Expand Up @@ -228,7 +213,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
* referenced from a different place in the object graph. */
recursion_rc = (zend_refcounted *)obj;
}
r = PHP_JSON_OUTPUT_OBJECT;
encode_as_object = true;
}

if (recursion_rc && GC_IS_RECURSIVE(recursion_rc)) {
Expand All @@ -240,7 +225,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,

PHP_JSON_HASH_PROTECT_RECURSION(recursion_rc);

if (r == PHP_JSON_OUTPUT_ARRAY) {
if (!encode_as_object) {
smart_str_appendc(buf, '[');
} else {
smart_str_appendc(buf, '{');
Expand All @@ -259,7 +244,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
zval tmp;
ZVAL_UNDEF(&tmp);

if (r == PHP_JSON_OUTPUT_ARRAY) {
if (!encode_as_object) {
ZEND_ASSERT(Z_TYPE_P(data) != IS_PTR);

if (need_comma) {
Expand All @@ -270,7 +255,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,

php_json_pretty_print_char(buf, options, '\n');
php_json_pretty_print_indent(buf, options, encoder);
} else if (r == PHP_JSON_OUTPUT_OBJECT) {
} else {
if (key) {
if (ZSTR_VAL(key)[0] == '\0' && ZSTR_LEN(key) > 0 && Z_TYPE_P(val) == IS_OBJECT) {
/* Skip protected and private members. */
Expand Down Expand Up @@ -354,7 +339,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
php_json_pretty_print_indent(buf, options, encoder);
}

if (r == PHP_JSON_OUTPUT_ARRAY) {
if (!encode_as_object) {
smart_str_appendc(buf, ']');
} else {
smart_str_appendc(buf, '}');
Expand All @@ -369,7 +354,6 @@ zend_result php_json_escape_string(
smart_str *buf, const char *s, size_t len,
int options, php_json_encoder *encoder) /* {{{ */
{
unsigned int us;
size_t pos, checkpoint;
char *dst;

Expand Down Expand Up @@ -407,7 +391,7 @@ zend_result php_json_escape_string(
0xffffffff, 0x500080c4, 0x10000000, 0x00000000,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};

us = (unsigned char)s[pos];
unsigned int us = (unsigned char)s[pos];
if (EXPECTED(!ZEND_BIT_TEST(charmap, us))) {
pos++;
len--;
Expand Down Expand Up @@ -626,7 +610,7 @@ static zend_result php_json_encode_serializable_object(smart_str *buf, zend_obje

static zend_result php_json_encode_serializable_enum(smart_str *buf, zval *val, int options, php_json_encoder *encoder)
{
zend_class_entry *ce = Z_OBJCE_P(val);
const zend_class_entry *ce = Z_OBJCE_P(val);
if (ce->enum_backing_type == IS_UNDEF) {
encoder->error_code = PHP_JSON_ERROR_NON_BACKED_ENUM;
smart_str_appendc(buf, '0');
Expand Down
4 changes: 0 additions & 4 deletions ext/json/php_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ typedef enum {
#define PHP_JSON_INVALID_UTF8_SUBSTITUTE (1<<21)
#define PHP_JSON_THROW_ON_ERROR (1<<22)

/* Internal flags */
#define PHP_JSON_OUTPUT_ARRAY 0
#define PHP_JSON_OUTPUT_OBJECT 1

/* default depth */
#define PHP_JSON_PARSER_DEFAULT_DEPTH 512

Expand Down
12 changes: 7 additions & 5 deletions ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
ExecStatusType status;

switch (ori) {
case PDO_FETCH_ORI_NEXT: spprintf(&ori_str, 0, "NEXT"); break;
case PDO_FETCH_ORI_PRIOR: spprintf(&ori_str, 0, "BACKWARD"); break;
case PDO_FETCH_ORI_FIRST: spprintf(&ori_str, 0, "FIRST"); break;
case PDO_FETCH_ORI_LAST: spprintf(&ori_str, 0, "LAST"); break;
case PDO_FETCH_ORI_NEXT: ori_str = "NEXT"; break;
case PDO_FETCH_ORI_PRIOR: ori_str = "BACKWARD"; break;
case PDO_FETCH_ORI_FIRST: ori_str = "FIRST"; break;
case PDO_FETCH_ORI_LAST: ori_str = "LAST"; break;
case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0, "ABSOLUTE " ZEND_LONG_FMT, offset); break;
case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0, "RELATIVE " ZEND_LONG_FMT, offset); break;
default:
Expand All @@ -542,7 +542,9 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
}

spprintf(&q, 0, "FETCH %s FROM %s", ori_str, S->cursor_name);
efree(ori_str);
if (ori == PDO_FETCH_ORI_ABS || ori == PDO_FETCH_ORI_REL) {
efree(ori_str);
}
S->result = PQexec(S->H->server, q);
efree(q);
status = PQresultStatus(S->result);
Expand Down
1 change: 1 addition & 0 deletions ext/posix/tests/posix_kill_pidoverflow.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
posix_kill() with large pid
--EXTENSIONS--
posix
pcntl
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
--FILE--
Expand Down
6 changes: 1 addition & 5 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,9 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,

/* protocol version we are speaking */
if (context && (tmpzval = php_stream_context_get_option(context, "http", "protocol_version")) != NULL) {
char *protocol_version;
spprintf(&protocol_version, 0, "%.1F", zval_get_double(tmpzval));

smart_str_appends(&req_buf, " HTTP/");
smart_str_appends(&req_buf, protocol_version);
smart_str_append_printf(&req_buf, "%.1F", zval_get_double(tmpzval));
smart_str_appends(&req_buf, "\r\n");
efree(protocol_version);
} else {
smart_str_appends(&req_buf, " HTTP/1.1\r\n");
}
Expand Down
8 changes: 5 additions & 3 deletions ext/sysvmsg/sysvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,12 @@ PHP_FUNCTION(msg_send)
message_len = spprintf(&p, 0, ZEND_LONG_FMT, Z_LVAL_P(message));
break;
case IS_FALSE:
message_len = spprintf(&p, 0, "0");
p = "0";
message_len = 1;
break;
case IS_TRUE:
message_len = spprintf(&p, 0, "1");
p = "1";
message_len = 1;
break;
case IS_DOUBLE:
message_len = spprintf(&p, 0, "%F", Z_DVAL_P(message));
Expand All @@ -400,7 +402,7 @@ PHP_FUNCTION(msg_send)
messagebuffer = safe_emalloc(message_len, 1, sizeof(struct php_msgbuf));
memcpy(messagebuffer->mtext, p, message_len + 1);

if (Z_TYPE_P(message) != IS_STRING) {
if (Z_TYPE_P(message) == IS_LONG || Z_TYPE_P(message) == IS_DOUBLE) {
efree(p);
}
}
Expand Down
13 changes: 7 additions & 6 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
const char *space = "";
const char *class_name = "";
const char *function;
int origin_len;
size_t origin_len;
char *origin;
zend_string *message;
int is_function = 0;
Expand Down Expand Up @@ -1116,9 +1116,10 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ

/* if we still have memory then format the origin */
if (is_function) {
origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
} else {
origin_len = (int)spprintf(&origin, 0, "%s", function);
origin_len = strlen(function);
origin = estrndup(function, origin_len);
}

if (PG(html_errors)) {
Expand All @@ -1135,14 +1136,14 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ

/* no docref given but function is known (the default) */
if (!docref && is_function) {
int doclen;
size_t doclen;
while (*function == '_') {
function++;
}
if (space[0] == '\0') {
doclen = (int)spprintf(&docref_buf, 0, "function.%s", function);
doclen = spprintf(&docref_buf, 0, "function.%s", function);
} else {
doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function);
doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function);
}
while((p = strchr(docref_buf, '_')) != NULL) {
*p = '-';
Expand Down
11 changes: 3 additions & 8 deletions sapi/fpm/fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,46 +1383,41 @@ static void fpm_conf_cleanup(int which, void *arg) /* {{{ */

static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */
{
char *filename;
int *error = (int *)arg;
php_glob_t g;
size_t i;

if (!inc || !arg) return;
if (*error) return; /* We got already an error. Switch to the end. */
spprintf(&filename, 0, "%s", ini_filename);

const char *filename = ini_filename;

{
g.gl_offs = 0;
if ((i = php_glob(inc, PHP_GLOB_ERR | PHP_GLOB_MARK, NULL, &g)) != 0) {
#ifdef PHP_GLOB_NOMATCH
if (i == PHP_GLOB_NOMATCH) {
zlog(ZLOG_WARNING, "Nothing matches the include pattern '%s' from %s at line %d.", inc, filename, ini_lineno);
efree(filename);
return;
}
#endif /* PHP_GLOB_NOMATCH */
zlog(ZLOG_ERROR, "Unable to globalize '%s' (ret=%zd) from %s at line %d.", inc, i, filename, ini_lineno);
*error = 1;
efree(filename);
return;
}

for (i = 0; i < g.gl_pathc; i++) {
int len = strlen(g.gl_pathv[i]);
size_t len = strlen(g.gl_pathv[i]);
if (len < 1) continue;
if (g.gl_pathv[i][len - 1] == '/') continue; /* don't parse directories */
if (0 > fpm_conf_load_ini_file(g.gl_pathv[i])) {
zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", g.gl_pathv[i], filename, ini_lineno);
*error = 1;
efree(filename);
return;
}
}
php_globfree(&g);
}

efree(filename);
}
/* }}} */

Expand Down
22 changes: 11 additions & 11 deletions sapi/phpdbg/phpdbg_prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
array_init(&params);

while (next) {
char *buffered = NULL;
zend_string *buffered = NULL;

switch (next->type) {
case OP_PARAM:
Expand All @@ -125,28 +125,28 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
break;

case METHOD_PARAM:
spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s::%s", next->method.class, next->method.name);
add_next_index_str(&params, buffered);
break;

case NUMERIC_METHOD_PARAM:
spprintf(&buffered, 0, "%s::%s#"ZEND_LONG_FMT, next->method.class, next->method.name, next->num);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s::%s#"ZEND_LONG_FMT, next->method.class, next->method.name, next->num);
add_next_index_str(&params, buffered);
break;

case NUMERIC_FUNCTION_PARAM:
spprintf(&buffered, 0, "%s#"ZEND_LONG_FMT, next->str, next->num);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s#"ZEND_LONG_FMT, next->str, next->num);
add_next_index_str(&params, buffered);
break;

case FILE_PARAM:
spprintf(&buffered, 0, "%s:"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s:"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_str(&params, buffered);
break;

case NUMERIC_FILE_PARAM:
spprintf(&buffered, 0, "%s:#"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s:#"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_str(&params, buffered);
break;

default: {
Expand Down
Loading