Skip to content

refactor: remove dead condition in session.c - #21939

Merged
Girgias merged 1 commit into
php:masterfrom
jorgsowa:fix/dead-if-for-id
May 4, 2026
Merged

refactor: remove dead condition in session.c#21939
Girgias merged 1 commit into
php:masterfrom
jorgsowa:fix/dead-if-for-id

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

PS(id) is always non-null and non-empty when it reaches the if.

@jorgsowa
jorgsowa requested a review from Girgias as a code ownerMay 3, 2026 13:01
@jorgsowajorgsowa changed the title fix: remove dead condition in session.crefactor: remove dead condition in session.cMay 3, 2026
Comment threadext/session/session.c
}

/* If there is no ID, use session module to create one */
if (!PS(id) || !ZSTR_VAL(PS(id))[0]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if PS(id) was falsey then this branch would be taken

Comment threadext/session/session.c
@@ -446,9 +446,7 @@
} else if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, is there any guarantee that s_validate_sid (which is given the PS(id) as a paremeter) doesn't make it falsey, either directly or by accessing the global?

It looks like the chain of zend_string_release_ex and on don't actually assert that the string is present - can I suggest adding a ZEND_ASSERT(PS(id)) so that if there is ever a case where the string is absent at least there is a clear failure in debug builds?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a violation of the API contract, and it requires someone to write a session storage module that purposefully fucks around with it.

I was working on trying to reduce the amount of global state in ext/session to limit those sort of problems.

@Girgias
Girgias merged commit 241767c into php:masterMay 4, 2026
19 checks passed
@jorgsowa
jorgsowa deleted the fix/dead-if-for-id branch July 10, 2026 14:29
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jorgsowa@Girgias@DanielEScherzer