Skip to content

Commit 0f3039b

Browse files
committed
fix: heap use-after-free for JS::UniqueChars
`JS::UniqueChars` will free the string buffer in its destructor, so it must be kept alive until the end of the function
1 parent c140da7 commit 0f3039b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/PyObjectProxyHandler.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ bool PyObjectProxyHandler::handleGetOwnPropertyDescriptor(JSContext *cx, JS::Han
4444
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc, PyObject *item) {
4545
// see if we're calling a function
4646
if (id.isString()) {
47-
JS::RootedString idString(cx, id.toString());
48-
const char *methodName = JS_EncodeStringToUTF8(cx, idString).get();
47+
JS::UniqueChars idString = JS_EncodeStringToUTF8(cx, JS::RootedString(cx, id.toString()));
48+
const char *methodName = idString.get();
49+
4950
if (!strcmp(methodName, "toString") || !strcmp(methodName, "toLocaleString") || !strcmp(methodName, "valueOf")) {
5051
JS::RootedObject objectPrototype(cx);
5152
if (!JS_GetClassPrototype(cx, JSProto_Object, &objectPrototype)) {

0 commit comments

Comments
 (0)