`moz_task::ThreadPtrHolder` passes an invalid C string to `NS_ProxyReleaseISupports`
Categories
(Core :: XPCOM, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox68 | --- | fixed |
People
(Reporter: lina, Assigned: lina)
References
(Regression)
Details
(Keywords: regression)
Attachments
(1 file)
This line casts a static string slice to a *const c_char
. But that's wrong—the string isn't NUL-terminated, so ProxyReleaseEvent::GetName
will read garbage. I'm surprised ASan didn't catch this, because...
I originally used a CString
for ThreadPtrHolder::name
, but that was also wrong. ProxyReleaseEvent
holds on to the name after the ThreadPtrHolder
is dropped, leading to this use after free.
We could:
-
Add a
nul_terminate!("foo")
macro that asserts a static string doesn't contain embedded NULs, then adds a trailing one.ThreadPtrHolder::new
will likewise want to assert that the string is NUL-terminated. -
Change
ProxyReleaseEvent
to hold annsCString
instead of aconst char*
. We'd need to changeRunnable
, too. -
Remove
ThreadPtrHolder::name
entirely, and passptr::null()
. Proxied releases from Rust won't log runnable names, so this is (probably?) not ideal. -
Something else?
Comment 1•6 years ago
|
||
(In reply to Lina Cambridge (she/her) [:lina] from comment #0)
We could:
- Add a
nul_terminate!("foo")
macro that asserts a static string doesn't contain embedded NULs, then adds a trailing one.ThreadPtrHolder::new
will likewise want to assert that the string is NUL-terminated.
I think this is probably the best option. Surely somebody has already written nul_terminate!
or something very like it.
- Change
ProxyReleaseEvent
to hold annsCString
instead of aconst char*
. We'd need to changeRunnable
, too.
This change would not be desirable, because then every runnable would need to construct and tear down an nsCString
, plus potential additional memory allocation. If the nsCString
requirement was contained to ProxyReleaseEvent
, that would be more doable.
- Remove
ThreadPtrHolder::name
entirely, and passptr::null()
. Proxied releases from Rust won't log runnable names, so this is (probably?) not ideal.
I'd prefer to avoid this.
Assignee | ||
Comment 2•6 years ago
|
||
This is based on the c_str!
macro in js/rust/src/heap.rs
, but
returns a byte slice instead of a pointer, so that it can be checked in
Rust without dereferencing.
This commit also changes ThreadPtrHolder::new
to assert that name
is a valid C string, and removes an unnecessary RefPtr
reference in
is_current_thread
.
Comment 4•6 years ago
|
||
bugherder |
Updated•6 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Description
•