Skip to content

Memory access within the null pointer with simplexml extension #14638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YuanchengJiang opened this issue Jun 23, 2024 · 0 comments
Closed

Memory access within the null pointer with simplexml extension #14638

YuanchengJiang opened this issue Jun 23, 2024 · 0 comments

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
function varToString($var) {
try {
if (is_object($var) && method_exists($var, '__toString')) {
}
return (string)$var;
} catch (Exception $e) {
}
}
function varToArray($var) {
try {
if (is_array($var)) {
}
} catch (Exception $e) {
}
}
function var_fusion($var1, $var2, $var3) {
$vars = [$var1, $var2, $var3];
foreach ($vars as $i => $v1) {
foreach ($vars as $j => $v2) {
if ($i < $j) {
try {
$result["concat_{$i}_{$j}"] = varToString($v1) . " " . varToString($v2);
} catch (Exception $e) {
}
try {
} catch (Exception $e) {
}
try {
if (is_object($v1) && method_exists($v1, 'toString')) {
}
if (is_object($v2) && property_exists($v2, 'value')) {
}
} catch (Exception $e) {
}
try {
if (is_callable($v1)) {
}
} catch (Exception $e) {
}
try {
if (is_callable($v2)) {
}
} catch (Exception $e) {
}
}
}
}
}
$xml = '<?xml version="1.0" encoding="utf-8" ?>
<test>
</test>';
$root = simplexml_load_string($xml);
$clone = clone $root;
$script1_dataflow = $clone;
$script1_connect=$clone;
class foo {
function __construct($n=0) {
}
}
try {
$y=$script1_dataflow->__construct(1);
} catch (Exception $e) {
}
var_fusion($script1_connect, $script2_connect, $random_var);

Resulted in this output:

/php-src/ext/simplexml/simplexml.c:1820:64: runtime error: member access within null pointer of type 'php_libxml_ref_obj' (aka 'struct _php_libxml_ref_obj')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/simplexml/simplexml.c:1820:64

PHP Version

nightly

Operating System

ubuntu 22.04

devnexen added a commit to devnexen/php-src that referenced this issue Jun 23, 2024
object document is null is the parsing had failed prior to cast to
string.
devnexen added a commit to devnexen/php-src that referenced this issue Jun 23, 2024
object document is null is the parsing had failed prior to cast to
string.
devnexen added a commit to devnexen/php-src that referenced this issue Jun 23, 2024
object document is null is the parsing had failed prior to cast to
string.
devnexen added a commit to devnexen/php-src that referenced this issue Jun 23, 2024
object document is null if the parsing had failed prior to cast to
string.
devnexen added a commit to devnexen/php-src that referenced this issue Jul 1, 2024
object document is null if the parsing had failed prior to cast to
string.
devnexen added a commit to devnexen/php-src that referenced this issue Jul 1, 2024
object document is null if the parsing had failed prior to cast to
string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants