Skip to content

Segmentation fault (access null pointer) in ext/dom/html5_serializer.c #15570

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
$html = <<<HTML
<head>
</html>
HTML;
$dom = Dom\HTMLDocument::createFromString($html);
$a = $dom->head->firstChild->cloneNode(false);
echo $dom->saveHTML($a), "\n";

Resulted in this output:

/php-src/ext/dom/html5_serializer.c:134:20: runtime error: member access within null pointer of type 'struct _xmlNode'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/dom/html5_serializer.c:134:20 in

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

Activity

  1. self-assigned this
    on Aug 24, 2024
  2. ndossche commented on Aug 24, 2024

    @ndossche
    Member

    Problem is that a text node does not necessarily have a parent if it's the outer node, and this is not checked, easily fixable.

  3. added a commit that references this issue on Aug 24, 2024
    8cc94d1
  4. added a commit that references this issue on Aug 25, 2024
    690ce6d
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