Skip to content

Potential integer underflow in format_converter() when precision < 0 and adjust_precision == true #18758

Open
@PavlNekrasov

Description

@PavlNekrasov

Description

Hi,

In the following code, possible precision variable value being set to -1 and adjust_precision == true:

php-src/main/snprintf.c

Lines 576 to 586 in 3a14ce1

adjust_precision = true;
fmt++;
if (isdigit((int)*fmt)) {
STR_TO_DEC(fmt, precision);
} else if (*fmt == '*') {
precision = va_arg(ap, int);
fmt++;
if (precision < -1)
precision = -1;
} else
precision = 0;

This can result undefined behavior when precision is later cast to size_t.

if (adjust_precision && (size_t)precision < s_len) {

Found by Linux Verification Center (linuxtesting.org) with SVACE.
Reporter: Pavel Nekrasov (p.nekrasov@fobos-nt.ru).
Organization: Fobos-NT (info@fobos-nt.ru).

PHP Version

PHP 8.3

Operating System

Alt p10

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