Skip to content
Open
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
8 changes: 4 additions & 4 deletions ext/session/mod_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# ifndef O_NOFOLLOW
# define O_NOFOLLOW 0
# endif
#define SESS_FILE_BUF_SIZE(sz) ((unsigned int)(sz > INT_MAX ? INT_MAX : (unsigned int)sz))
#define SESS_FILE_BUF_SIZE(sz) ((unsigned int)(UNEXPECTED((sz) > INT_MAX) ? INT_MAX : (unsigned int)sz))
#endif

typedef struct {
Expand Down Expand Up @@ -292,7 +292,7 @@ static int ps_files_cleanup_dir(const zend_string *dirname, zend_long maxlifetim
return -1;
}

if (ZSTR_LEN(dirname) >= MAXPATHLEN) {
if (UNEXPECTED(ZSTR_LEN(dirname) >= MAXPATHLEN)) {
php_error_docref(NULL, E_NOTICE, "ps_files_cleanup_dir: dirname(%s) is too long", ZSTR_VAL(dirname));
closedir(dir);
return -1;
Expand Down Expand Up @@ -413,7 +413,7 @@ PS_OPEN_FUNC(files)
if (argc > 1) {
errno = 0;
dirdepth = (size_t) ZEND_STRTOL(argv[0], NULL, 10);
if (errno == ERANGE) {
if (UNEXPECTED(errno == ERANGE)) {
php_error(E_WARNING, "The first parameter in session.save_path is invalid");
return FAILURE;
}
Expand All @@ -422,7 +422,7 @@ PS_OPEN_FUNC(files)
if (argc > 2) {
errno = 0;
filemode = (int)ZEND_STRTOL(argv[1], NULL, 8);
if (errno == ERANGE || filemode < 0 || filemode > 07777) {
if (UNEXPECTED(errno == ERANGE || filemode < 0 || filemode > 07777)) {
php_error(E_WARNING, "The second parameter in session.save_path is invalid");
return FAILURE;
}
Expand Down
10 changes: 5 additions & 5 deletions ext/session/mod_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static ps_sd *ps_sd_new(ps_mm *data, zend_string *key)
ps_sd *sd;

sd = mm_malloc(data->mm, sizeof(ps_sd) + ZSTR_LEN(key));
if (!sd) {
if (UNEXPECTED(!sd)) {

php_error_docref(NULL, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), mm_error());
return NULL;
Expand Down Expand Up @@ -222,14 +222,14 @@ static zend_result ps_mm_initialize(ps_mm *data, const char *path)
{
data->owner = getpid();
data->mm = mm_create(0, path);
if (!data->mm) {
if (UNEXPECTED(!data->mm)) {
return FAILURE;
}

data->hash_cnt = 0;
data->hash_max = 511;
data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *));
if (!data->hash) {
if (UNEXPECTED(!data->hash)) {
mm_destroy(data->mm);
return FAILURE;
}
Expand Down Expand Up @@ -269,7 +269,7 @@ PHP_MINIT_FUNCTION(ps_mm)
zend_result ret;

ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
if (!ps_mm_instance) {
if (UNEXPECTED(!ps_mm_instance)) {
return FAILURE;
}

Expand Down Expand Up @@ -376,7 +376,7 @@ PS_WRITE_FUNC(mm)
sd->alloclen = val->len + 1;
sd->data = mm_malloc(data->mm, sd->alloclen);

if (!sd->data) {
if (UNEXPECTED(!sd->data)) {
ps_sd_destroy(data, sd);
php_error_docref(NULL, E_WARNING, "Cannot allocate new data segment");
sd = NULL;
Expand Down
4 changes: 2 additions & 2 deletions ext/session/mod_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ps_module ps_mod_user = {
static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
{
int i;
if (PS(in_save_handler)) {
if (UNEXPECTED(PS(in_save_handler))) {
PS(in_save_handler) = false;
ZVAL_UNDEF(retval);
php_error_docref(NULL, E_WARNING, "Cannot call session save handler in a recursive manner");
Expand Down Expand Up @@ -237,7 +237,7 @@ PS_CREATE_SID_FUNC(user)
return NULL;
}

if (!id) {
if (UNEXPECTED(!id)) {
zend_throw_error(NULL, "Session id must be a string");
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/session/php_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ PHPAPI zend_result php_session_reset_id(void);
/* protect against user interference */ \
ZVAL_COPY(&_zv, Z_REFVAL(PS(http_session_vars))); \
ZEND_HASH_FOREACH_KEY(Z_ARRVAL(_zv), zend_ulong num_key, zend_string * key) { \
if (key == NULL) { \
if (UNEXPECTED(key == NULL)) { \
php_error_docref(NULL, E_WARNING, \
"Skipping numeric key " ZEND_LONG_FMT, num_key); \
continue; \
Expand Down
22 changes: 11 additions & 11 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ PHPAPI zend_result php_session_valid_key(const char *key)

for (p = key; (c = *p); p++) {
/* valid characters are [a-z], [A-Z], [0-9], - (hyphen) and , (comma) */
if (!((c >= 'a' && c <= 'z')
if (UNEXPECTED(!((c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9')
|| c == ','
|| c == '-')) {
|| c == '-'))) {
return FAILURE;
}
}
Expand All @@ -378,7 +378,7 @@ PHPAPI zend_result php_session_valid_key(const char *key)

/* Somewhat arbitrary length limit here, but should be way more than
anyone needs and avoids file-level warnings later on if we exceed MAX_PATH */
if (key_len == 0 || key_len > PS_MAX_SID_LENGTH) {
if (UNEXPECTED(key_len == 0 || key_len > PS_MAX_SID_LENGTH)) {
return FAILURE;
}

Expand Down Expand Up @@ -728,7 +728,7 @@ static PHP_INI_MH(OnUpdateCookieLifetime)
}
return FAILURE;
}
if (lval < 0 || lval > maxcookie) {
if (UNEXPECTED(lval < 0 || lval > maxcookie)) {
php_error_docref(NULL, E_WARNING, "session.cookie_lifetime must be between 0 and " ZEND_LONG_FMT, maxcookie);
return FAILURE;
}
Expand Down Expand Up @@ -795,7 +795,7 @@ static PHP_INI_MH(OnUpdateSidLength)
php_error_docref("session.configuration", E_DEPRECATED, "session.sid_length INI setting is deprecated");
}

if (!endptr || (*endptr != '\0') || (val < 22) || (val > PS_MAX_SID_LENGTH)) {
if (UNEXPECTED(!endptr || (*endptr != '\0') || (val < 22) || (val > PS_MAX_SID_LENGTH))) {
php_error_docref(NULL, E_WARNING, "session.configuration \"session.sid_length\" must be between 22 and 256");
return FAILURE;
}
Expand All @@ -819,7 +819,7 @@ static PHP_INI_MH(OnUpdateSidBits)
php_error_docref("session.configuration", E_DEPRECATED, "session.sid_bits_per_character INI setting is deprecated");
}

if (!endptr || (*endptr != '\0') || (val < 4) || (val > 6)) {
if (UNEXPECTED(!endptr || (*endptr != '\0') || (val < 4) || (val > 6))) {
php_error_docref(NULL, E_WARNING, "session.configuration \"session.sid_bits_per_character\" must be between 4 and 6");
return FAILURE;
}
Expand All @@ -836,7 +836,7 @@ static PHP_INI_MH(OnUpdateSessionGcProbability)

zend_long new_probability = zend_ini_parse_quantity_warn(new_value, entry->name);

if (new_probability < 0) {
if (UNEXPECTED(new_probability < 0)) {
php_error_docref("session.gc_probability", E_WARNING, "session.gc_probability must be greater than or equal to 0");
return FAILURE;
}
Expand All @@ -854,7 +854,7 @@ static PHP_INI_MH(OnUpdateSessionDivisor)

zend_long new_divisor = zend_ini_parse_quantity_warn(new_value, entry->name);

if (new_divisor <= 0) {
if (UNEXPECTED(new_divisor <= 0)) {
php_error_docref("session.gc_divisor", E_WARNING, "session.gc_divisor must be greater than 0");
return FAILURE;
}
Expand All @@ -869,13 +869,13 @@ static PHP_INI_MH(OnUpdateRfc1867Freq)
{
int new_freq = ZEND_ATOL(ZSTR_VAL(new_value));

if (new_freq < 0) {
if (UNEXPECTED(new_freq < 0)) {
php_error_docref(NULL, E_WARNING, "session.upload_progress.freq must be greater than or equal to 0");
return FAILURE;
}

if (ZSTR_LEN(new_value) > 0 && ZSTR_VAL(new_value)[ZSTR_LEN(new_value) - 1] == '%') {
if (new_freq > 100) {
if (UNEXPECTED(new_freq > 100)) {
php_error_docref(NULL, E_WARNING, "session.upload_progress.freq must be less than or equal to 100%%");
return FAILURE;
}
Expand Down Expand Up @@ -2464,7 +2464,7 @@ PHP_FUNCTION(session_create_id)
}

if (prefix && ZSTR_LEN(prefix)) {
if (ZSTR_LEN(prefix) > PS_MAX_SID_LENGTH) {
if (UNEXPECTED(ZSTR_LEN(prefix) > PS_MAX_SID_LENGTH)) {
zend_argument_value_error(1, "cannot be longer than %d characters", PS_MAX_SID_LENGTH);
RETURN_THROWS();
}
Expand Down
Loading