Skip to content

Commit 4177257

Browse files
authored
3 minor cleanups in ext/session (php#10722)
* 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.
1 parent f247e48 commit 4177257

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

ext/session/mod_files.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,8 @@ PS_CREATE_SID_FUNC(files)
674674
/* Check collision */
675675
/* FIXME: mod_data(data) should not be NULL (User handler could be NULL) */
676676
if (data && ps_files_key_exists(data, sid) == SUCCESS) {
677-
if (sid) {
678-
zend_string_release_ex(sid, 0);
679-
sid = NULL;
680-
}
677+
zend_string_release_ex(sid, 0);
678+
sid = NULL;
681679
if (--maxfail < 0) {
682680
return NULL;
683681
}

ext/session/session.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,9 @@ PS_SERIALIZER_DECODE_FUNC(php_binary) /* {{{ */
904904
PHP_VAR_UNSERIALIZE_INIT(var_hash);
905905

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

910-
if (namelen < 0 || namelen > PS_BIN_MAX || (p + namelen) >= endptr) {
909+
if (namelen > PS_BIN_MAX || (p + namelen) >= endptr) {
911910
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
912911
return FAILURE;
913912
}
@@ -2910,7 +2909,7 @@ static PHP_MINFO_FUNCTION(session) /* {{{ */
29102909

29112910
/* Get serializer handlers */
29122911
for (i = 0, ser = ps_serializers; i < MAX_SERIALIZERS; i++, ser++) {
2913-
if (ser && ser->name) {
2912+
if (ser->name) {
29142913
smart_str_appends(&ser_handlers, ser->name);
29152914
smart_str_appendc(&ser_handlers, ' ');
29162915
}

0 commit comments

Comments
 (0)