Skip to content

pestr(n)dup() is not infallible #9128

Closed
@cmb69

Description

@cmb69

Description

In case persistent allocation is requested, neither pestrdup() nor pestrndup() are infallible. They are defined as

php-src/Zend/zend_alloc.h

Lines 204 to 205 in a05a6c5

#define pestrdup(s, persistent) ((persistent)?strdup(s):estrdup(s))
#define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))

However, neither strdup(3) nor zend_strndup() are infallible:

php-src/Zend/zend_alloc.c

Lines 2671 to 2673 in a05a6c5

if (UNEXPECTED(p == NULL)) {
return p;
}

This is, of course, not a problem per se, but it would mean that all calls to these functions would need to be guarded by NULL checks.

PHP Version

PHP-8.0

Operating System

any

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