Explicitly default-initialize local variables generated by IPDL
Categories
(Core :: IPC, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox82 | --- | fixed |
People
(Reporter: nika, Assigned: nika)
References
Details
Attachments
(1 file)
Doing this helps lower the chances of accidentally trying to send an uninitialized primitive value, like a raw pointer or integer, over IPC due to a sync method or IPDLParamTraits::Read implementation failing to initialize the outparameter.
This would avoid potential errors like those fixed in bug 1664323 from recurring.
| Assignee | ||
Comment 1•6 years ago
|
||
Doing this helps lower the chances of accidentally trying to send an
uninitialized primitive value, like a raw pointer or integer, over IPC due to a
sync method or IPDLParamTraits::Read implementation failing to initialize the
outparameter.
Comment 3•6 years ago
|
||
| bugherder | ||
Comment 4•6 years ago
|
||
Hm, I am not sure if that's really a good idea. While this would have "fixed" bug 1664323, I think it's more appropriate to say this would have masked bug 1664323, and will mask similar errors. In general, it's not set that the default value is sensible (for pointers, it might still make sense to initialize them to nullptr for security reasons, but for other types I doubt that). It's a general problem of output parameters that it's ambiguous of what to assume about their value on call. An alternative (or rather follow-up) to doing this, would be to replace output parameters by return values altogether (maybe using mozilla::Result), which avoids masking such mistakes, and them not impossible but much less likely, and also reduces the chances of brain overload due to the ambiguities of output parameters. Unfortunately, this will probably require quite extensive changes across the codebase.
| Assignee | ||
Comment 5•6 years ago
|
||
I don't think this counts as "masking" an issue - it's turning a bug from being something buggy which sends uninitialized memory over IPC to a bug which doesn't interact with uninitialized memory. Callers should obviously still initialize their outparameters, but it's now much less likely to cause serious issues in untested edge-cases down the line if someone forgets (which is somewhat easy to do).
The nicer solution of using mozilla::Result instead of an outparameter sounds nice, but I don't think it's worth doing. The particular codepath we're talking about here is for sync IPC, which is somewhat uncommon in our codebase, quite error-prone, and we're explicitly trying to avoid adding new users of. I think it's OK to continue to have bad ergonomics for sync IPC, and it's not worth the effort to make it nicer to use.
Comment 6•6 years ago
|
||
I wasn't aware that this is only relevant for a few cases. Then I also thinik it's not worth changing this.
Description
•