Re:Virtually Unlimited Memory: Escaping the Chrome Sandbox
by saagarjha on Monday April 15, 2019 @06:40PM
(#19669546)
Note that the bug was caused by broken code that creates an unsafe, unretained reference to a smart pointer.
[ Parent
| on HN ]
Re:Virtually Unlimited Memory: Escaping the Chrome Sandbox
by pcwalton on Monday April 15, 2019 @06:42PM
(#19669559)
Which you do in C++ every time you use an &-reference.
Re:Virtually Unlimited Memory: Escaping the Chrome Sandbox
by comex on Monday April 15, 2019 @07:20PM
(#19669743)
True, but in this case the buggy code had to explicitly write "base::Unretained" because the callback system (base::BindOnce) performs additional checks.
Re:Virtually Unlimited Memory: Escaping the Chrome Sandbox
by saagarjha on Monday April 15, 2019 @06:52PM
(#19669603)
But that's not modern C++ anymore–the whole point is to have RAII manage your pointer's lifetime so it doesn't dangle.
Re:Virtually Unlimited Memory: Escaping the Chrome Sandbox
by pcwalton on Monday April 15, 2019 @10:06PM
(#19670551)
References are absolutely modern C++. There isn't a nontrivial C++ program in existence that doesn't use references.
Re:Virtually Unlimited Memory: Escaping the Chrome Sandbox
by int_19h on Tuesday April 16, 2019 @02:41PM
(#19676156)
Yes, and most of those references are to locals that are passed as arguments to function calls that will never take their address. In other words, it's pass-by-ref - which is perfectly safe - not pointers.
To obtain a reference to an object that is managed by a smart pointer, you would have to, at the minimum, explicitly dereference that pointer with *. In most cases, this also happens in an argument context, and the caller will maintain the pointer. It breaks when the pointer that's managing lifetime is a part of mutable state that the callee can touch somehow without returning - then it can cause the object to be freed while still holding a non-counting reference to it. At that point, you basically need something like Rust lifetime/ownership tracking to prevent such unsafe situations from happening.