Skip to content

Potential overflow and sign-extension issues in posix_times() when converting clock_t to zend_long #18841

Open
@DehartShow

Description

@DehartShow

Description

There is a potential security issue when converting clock_t to zend_long that could lead to unpredictable results on different platforms. Platform dependencies of clock_t size: The size of clock_t is not fixed by the C standard, and may differ between systems (32-bit and 64-bit). Sign extension: If clock_t is smaller than zend_long, and clock_t is a signed type, then sign extension may occur when converting to zend_long, leading to incorrect interpretation of the values.

php-src/ext/posix/posix.c

Lines 386 to 390 in 28a083b

add_assoc_long(return_value, "ticks", ticks); /* clock ticks */
add_assoc_long(return_value, "utime", t.tms_utime); /* user time */
add_assoc_long(return_value, "stime", t.tms_stime); /* system time */
add_assoc_long(return_value, "cutime", t.tms_cutime); /* user time of children */
add_assoc_long(return_value, "cstime", t.tms_cstime); /* system time of children */

Found using SVACE
Author D. Chizhmak

PHP Version

PHP 8.3+

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions