1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:57:45 +00:00

LibJS: Fix UB downcast during GlobalObject construction

When constructing a GlobalObject, it has to pass itself as the global
object to its own Shape. Since this is done in the Object constructor,
and Object is a base class of GlobalObject, it's not yet valid to cast
"this" to a GlobalObject*.

Fix this by having Shape store the global object as an Object& and move
Shape::global_object() to GlobalObject.h where we can at least perform a
valid static_cast in the getter.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29267
This commit is contained in:
Andreas Kling 2021-01-05 12:02:59 +01:00
parent 279d2eee04
commit fdd974b7ef
4 changed files with 10 additions and 5 deletions

View file

@ -65,7 +65,7 @@ public:
enum class ShapeWithoutGlobalObjectTag { Tag };
explicit Shape(ShapeWithoutGlobalObjectTag);
explicit Shape(GlobalObject&);
explicit Shape(Object& global_object);
Shape(Shape& previous_shape, const StringOrSymbol& property_name, PropertyAttributes attributes, TransitionType);
Shape(Shape& previous_shape, Object* new_prototype);
@ -78,7 +78,7 @@ public:
bool is_unique() const { return m_unique; }
Shape* create_unique_clone() const;
GlobalObject* global_object() const { return m_global_object; }
GlobalObject* global_object() const;
Object* prototype() { return m_prototype; }
const Object* prototype() const { return m_prototype; }
@ -110,7 +110,7 @@ private:
TransitionType m_transition_type : 6 { TransitionType::Invalid };
bool m_unique : 1 { false };
GlobalObject* m_global_object { nullptr };
Object* m_global_object { nullptr };
mutable OwnPtr<HashMap<StringOrSymbol, PropertyMetadata>> m_property_table;