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
23 changes: 6 additions & 17 deletions ext/session/mod_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const ps_module ps_mod_files = {
PS_MOD_UPDATE_TIMESTAMP(files)
};


static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const zend_string *key)
{
const char *p;
Expand Down Expand Up @@ -153,7 +152,7 @@ static void ps_files_open(ps_files *data, /* const */ zend_string *key)
{
char buf[MAXPATHLEN];
#if !defined(O_NOFOLLOW) || !defined(PHP_WIN32)
struct stat sbuf = {0};
struct stat sbuf = {0};
#endif
int ret;

Expand Down Expand Up @@ -183,7 +182,7 @@ static void ps_files_open(ps_files *data, /* const */ zend_string *key)
#else
/* Check to make sure that the opened file is not outside of allowable dirs.
This is not 100% safe but it's hard to do something better without O_NOFOLLOW */
if(PG(open_basedir) && lstat(buf, &sbuf) == 0 && S_ISLNK(sbuf.st_mode) && php_check_open_basedir(buf)) {
if (PG(open_basedir) && lstat(buf, &sbuf) == 0 && S_ISLNK(sbuf.st_mode) && php_check_open_basedir(buf)) {
return;
}
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode);
Expand Down Expand Up @@ -230,7 +229,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string

/* PS(id) may be changed by calling session_regenerate_id().
Re-initialization should be tried here. ps_files_open() checks
data->last_key and reopen when it is needed. */
data->last_key and reopen when it is needed. */
ps_files_open(data, key);
if (data->fd < 0) {
return FAILURE;
Expand Down Expand Up @@ -258,7 +257,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
buf = wrote > -1 ? buf + wrote : 0;
to_write = wrote > -1 ? SESS_FILE_BUF_SIZE(ZSTR_LEN(val) - n) : 0;

} while(wrote > 0);
} while (wrote > 0);
}
#else
n = write(data->fd, ZSTR_VAL(val), ZSTR_LEN(val));
Expand Down Expand Up @@ -346,10 +345,8 @@ static zend_result ps_files_key_exists(ps_files *data, const zend_string *key)
return SUCCESS;
}


#define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()


/*
* Open save handler. Setup resources that are needed by the handler.
* PARAMETERS: PS_OPEN_ARGS in php_session.h
Expand Down Expand Up @@ -427,7 +424,6 @@ PS_OPEN_FUNC(files)
return SUCCESS;
}


/*
* Clean up opened resources.
* PARAMETERS: PS_CLOSE_ARGS in php_session.h
Expand Down Expand Up @@ -456,7 +452,6 @@ PS_CLOSE_FUNC(files)
return SUCCESS;
}


/*
* Read session data from opened resource.
* PARAMETERS: PS_READ_ARGS in php_session.h
Expand Down Expand Up @@ -508,7 +503,7 @@ PS_READ_FUNC(files)
buf = read_in > -1 ? buf + read_in : 0;
to_read = read_in > -1 ? SESS_FILE_BUF_SIZE(ZSTR_LEN(*val) - n) : 0;

} while(read_in > 0);
} while (read_in > 0);

}
#else
Expand All @@ -531,7 +526,6 @@ PS_READ_FUNC(files)
return SUCCESS;
}


/*
* Write session data.
* PARAMETERS: PS_WRITE_ARGS in php_session.h
Expand All @@ -547,7 +541,6 @@ PS_WRITE_FUNC(files)
return ps_files_write(data, key, val);
}


/*
* Update session data modification/access time stamp.
* PARAMETERS: PS_UPDATE_TIMESTAMP_ARGS in php_session.h
Expand Down Expand Up @@ -582,7 +575,6 @@ PS_UPDATE_TIMESTAMP_FUNC(files)
return SUCCESS;
}


/*
* Delete session data.
* PARAMETERS: PS_DESTROY_ARGS in php_session.h
Expand Down Expand Up @@ -617,7 +609,6 @@ PS_DESTROY_FUNC(files)
return SUCCESS;
}


/*
* Cleanup expired session data.
* PARAMETERS: PS_GC_ARGS in php_session.h
Expand Down Expand Up @@ -646,7 +637,6 @@ PS_GC_FUNC(files)
return *nrdels;
}


/*
* Create session ID.
* PARAMETERS: PS_CREATE_SID_ARGS in php_session.h
Expand Down Expand Up @@ -684,12 +674,11 @@ PS_CREATE_SID_FUNC(files)
return NULL;
}
}
} while(!sid);
} while (!sid);

return sid;
}


/*
* Check session ID existence for use_strict_mode support.
* PARAMETERS: PS_VALIDATE_SID_ARGS in php_session.h
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 @@ -40,11 +40,11 @@

typedef struct ps_sd {
struct ps_sd *next;
uint32_t hv; /* hash value of key */
time_t ctime; /* time of last change */
uint32_t hv; /* hash value of key */
time_t ctime; /* time of last change */
void *data;
size_t datalen; /* amount of valid data */
size_t alloclen; /* amount of allocated memory for data */
size_t datalen; /* amount of valid data */
size_t alloclen; /* amount of allocated memory for data */
zend_string *key;
} ps_sd;

Expand Down Expand Up @@ -464,7 +464,7 @@ PS_CREATE_SID_FUNC(mm)
return NULL;
}
}
} while(!sid);
} while (!sid);

return sid;
}
Expand Down
7 changes: 3 additions & 4 deletions ext/session/mod_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const ps_module ps_mod_user = {
PS_MOD_UPDATE_TIMESTAMP(user)
};


static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
{
int i;
Expand All @@ -47,7 +46,7 @@ static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)

#define PSF(a) PS(mod_user_names).ps_##a

static zend_result verify_bool_return_type_userland_calls(const zval* value)
static zend_result verify_bool_return_type_userland_calls(const zval *value)
{
/* Exit or exception in userland call */
if (Z_TYPE_P(value) == IS_UNDEF) {
Expand Down Expand Up @@ -75,8 +74,8 @@ static zend_result verify_bool_return_type_userland_calls(const zval* value)
}
if (!EG(exception)) {
zend_type_error("Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value)); \
}
return FAILURE;
}
return FAILURE;
}

PS_OPEN_FUNC(user)
Expand Down
10 changes: 5 additions & 5 deletions ext/session/mod_user_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "php.h"
#include "php_session.h"

#define PS_SANITY_CHECK \
#define PS_SANITY_CHECK \
if (PS(session_status) != php_session_active) { \
zend_throw_error(NULL, "Session is not active"); \
RETURN_THROWS(); \
Expand All @@ -27,11 +27,11 @@
RETURN_THROWS(); \
}

#define PS_SANITY_CHECK_IS_OPEN \
#define PS_SANITY_CHECK_IS_OPEN \
PS_SANITY_CHECK; \
if (!PS(mod_user_is_open)) { \
php_error_docref(NULL, E_WARNING, "Parent session handler is not open"); \
RETURN_FALSE; \
if (!PS(mod_user_is_open)) { \
php_error_docref(NULL, E_WARNING, "Parent session handler is not open"); \
RETURN_FALSE; \
}

PHP_METHOD(SessionHandler, open)
Expand Down
57 changes: 28 additions & 29 deletions ext/session/php_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ typedef struct ps_module_struct {
#define PS_GET_MOD_DATA() *mod_data
#define PS_SET_MOD_DATA(a) *mod_data = (a)

#define PS_OPEN_FUNC(x) zend_result ps_open_##x(PS_OPEN_ARGS)
#define PS_CLOSE_FUNC(x) zend_result ps_close_##x(PS_CLOSE_ARGS)
#define PS_READ_FUNC(x) zend_result ps_read_##x(PS_READ_ARGS)
#define PS_WRITE_FUNC(x) zend_result ps_write_##x(PS_WRITE_ARGS)
#define PS_DESTROY_FUNC(x) zend_result ps_delete_##x(PS_DESTROY_ARGS)
#define PS_GC_FUNC(x) zend_long ps_gc_##x(PS_GC_ARGS)
#define PS_CREATE_SID_FUNC(x) zend_string *ps_create_sid_##x(PS_CREATE_SID_ARGS)
#define PS_VALIDATE_SID_FUNC(x) zend_result ps_validate_sid_##x(PS_VALIDATE_SID_ARGS)
#define PS_UPDATE_TIMESTAMP_FUNC(x) zend_result ps_update_timestamp_##x(PS_UPDATE_TIMESTAMP_ARGS)
#define PS_OPEN_FUNC(x) zend_result ps_open_##x(PS_OPEN_ARGS)
#define PS_CLOSE_FUNC(x) zend_result ps_close_##x(PS_CLOSE_ARGS)
#define PS_READ_FUNC(x) zend_result ps_read_##x(PS_READ_ARGS)
#define PS_WRITE_FUNC(x) zend_result ps_write_##x(PS_WRITE_ARGS)
#define PS_DESTROY_FUNC(x) zend_result ps_delete_##x(PS_DESTROY_ARGS)
#define PS_GC_FUNC(x) zend_long ps_gc_##x(PS_GC_ARGS)
#define PS_CREATE_SID_FUNC(x) zend_string *ps_create_sid_##x(PS_CREATE_SID_ARGS)
#define PS_VALIDATE_SID_FUNC(x) zend_result ps_validate_sid_##x(PS_VALIDATE_SID_ARGS)
#define PS_UPDATE_TIMESTAMP_FUNC(x) zend_result ps_update_timestamp_##x(PS_UPDATE_TIMESTAMP_ARGS)

/* Save handler module definitions without timestamp enabled */
#define PS_FUNCS(x) \
Expand All @@ -69,7 +69,7 @@ typedef struct ps_module_struct {
PS_READ_FUNC(x); \
PS_WRITE_FUNC(x); \
PS_DESTROY_FUNC(x); \
PS_GC_FUNC(x); \
PS_GC_FUNC(x); \
PS_CREATE_SID_FUNC(x); \
PS_VALIDATE_SID_FUNC(x);

Expand All @@ -95,7 +95,6 @@ typedef struct ps_module_struct {
ps_delete_##x, ps_gc_##x, ps_create_sid_##x, \
ps_validate_sid_##x, ps_update_timestamp_##x


typedef enum {
php_session_disabled,
php_session_none,
Expand All @@ -115,8 +114,8 @@ typedef struct _php_session_rfc1867_progress {

zval data; /* the array exported to session data */
zval files; /* data["files"] array */
zval *post_bytes_processed; /* data["bytes_processed"] */
zval *current_file_bytes_processed;
zval *post_bytes_processed; /* data["bytes_processed"] */
zval *current_file_bytes_processed;
zval current_file; /* array of currently uploading file */
} php_session_rfc1867_progress;

Expand Down Expand Up @@ -256,23 +255,23 @@ PHPAPI zend_result php_session_reset_id(void);

/* Do not use a return statement in `code` because that may leak memory.
* Break out of the loop instead. */
#define PS_ENCODE_LOOP(code) do { \
zval _zv; \
/* protect against user interference */ \
ZVAL_COPY(&_zv, Z_REFVAL(PS(http_session_vars))); \
#define PS_ENCODE_LOOP(code) do { \
zval _zv; \
/* 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) { \
php_error_docref(NULL, E_WARNING, \
"Skipping numeric key " ZEND_LONG_FMT, num_key);\
continue; \
} \
zval *struc = php_get_session_var(key); \
if (struc) { \
code; \
} \
} ZEND_HASH_FOREACH_END(); \
zval_ptr_dtor(&_zv); \
} while(0)
if (key == NULL) { \
php_error_docref(NULL, E_WARNING, \
"Skipping numeric key " ZEND_LONG_FMT, num_key); \
continue; \
} \
zval *struc = php_get_session_var(key); \
if (struc) { \
code; \
} \
} ZEND_HASH_FOREACH_END(); \
zval_ptr_dtor(&_zv); \
} while (0)

PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps)

Expand Down
Loading
Loading