Skip to content

Commit

Permalink
3 minor cleanups in ext/session (#10722)
Browse files Browse the repository at this point in the history
* sid can never be NULL because it was NULL-checked earlier

* Change namelen to size_t because it is always unsigned and less in size than size_t

* Remove redundant check on ser

It can't be NULL, and even if it could, the ser++ would be UB.
  • Loading branch information
nielsdos committed Feb 28, 2023
1 parent f247e48 commit 4177257
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions ext/session/mod_files.c
Expand Up @@ -674,10 +674,8 @@ PS_CREATE_SID_FUNC(files)
/* Check collision */
/* FIXME: mod_data(data) should not be NULL (User handler could be NULL) */
if (data && ps_files_key_exists(data, sid) == SUCCESS) {
if (sid) {
zend_string_release_ex(sid, 0);
sid = NULL;
}
zend_string_release_ex(sid, 0);
sid = NULL;
if (--maxfail < 0) {
return NULL;
}
Expand Down
7 changes: 3 additions & 4 deletions ext/session/session.c
Expand Up @@ -904,10 +904,9 @@ PS_SERIALIZER_DECODE_FUNC(php_binary) /* {{{ */
PHP_VAR_UNSERIALIZE_INIT(var_hash);

for (p = val; p < endptr; ) {
// Can this be changed to size_t?
int namelen = ((unsigned char)(*p)) & (~PS_BIN_UNDEF);
size_t namelen = ((unsigned char)(*p)) & (~PS_BIN_UNDEF);

if (namelen < 0 || namelen > PS_BIN_MAX || (p + namelen) >= endptr) {
if (namelen > PS_BIN_MAX || (p + namelen) >= endptr) {
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return FAILURE;
}
Expand Down Expand Up @@ -2910,7 +2909,7 @@ static PHP_MINFO_FUNCTION(session) /* {{{ */

/* Get serializer handlers */
for (i = 0, ser = ps_serializers; i < MAX_SERIALIZERS; i++, ser++) {
if (ser && ser->name) {
if (ser->name) {
smart_str_appends(&ser_handlers, ser->name);
smart_str_appendc(&ser_handlers, ' ');
}
Expand Down

0 comments on commit 4177257

Please sign in to comment.