Skip to content

integer overflow in session.c:1353 #16290

Closed

Description

@chongwick

Description

The following code:

<?php
session_set_cookie_params(PHP_INT_MAX, '/', null, false, true);
session_start();
?>

Resulted in this output:

/home/dan/php-8.3.9/ext/session/session.c:1353:5: runtime error: signed integer overflow: 1728342208 + 9223372036854775807 cannot be represented in type 'long int'

Also, not tested with 8.3.12, yet.

PHP Version

8.3.9

Operating System

No response

Activity

  1. MarcusXavierr commented on Oct 8, 2024

    @MarcusXavierr
    Contributor

    I've tested it on a docker container with PHP 8.3.9 and went fine
    image

    I've also tested on my machine with PHP 8.2.15 and also didn't had any problem

    Did you make any steps besides running this code?

  2. MarcusXavierr commented on Oct 8, 2024

    @MarcusXavierr
    Contributor

    Maybe the error occurs because the PS(cookie_lifetime) is already the max positive size of long.
    image

    But why does this overflow doesn't break anything on my machine?

    And if the overflow is the problem, and the user can set cookie_lifetime to the max long int value, what are our options? Turning t into unsigned long?
    Test the possible overflow before assigning t, and treating the overflow case with the LONG_MAX value from limits.h?

  3. self-assigned this
    on Oct 8, 2024
  4. cmb69 commented on Oct 8, 2024

    @cmb69
    Member

    But why does this overflow doesn't break anything on my machine?

    That overflow is undefined behavior; it may not necessarily cause issues, but should be fixed nonetheless. To reliably detect it, you either need to debug manually, or to employ something like UBSan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions