4 ms·
> That said, typical C++ applications might be easier to get right than Javascript runtimes, JIT's, or whatever. A lot of eyes go into the JS foundations but so
by pcwalton 11y ago
> That said, typical C++ applications might be easier to get right than Javascript runtimes, JIT's, or whatever. A lot of eyes go into the JS foundations but so do a lot of complexity and problems.
It is untrue that typical JavaScript applications are vulnerable to anywhere near as many memory safety issues as C++ applications are. Even "modern C++".
As a very relevant example, closures are modern C++, but neglecting the right annotation on the capture clause—the difference between writing one ampersand and not—can lead to use-after-free. In JavaScript, the runtime will manage the lifetimes of the closed-over variables for you, and you can't get it wrong unless there's a bug in the JS engine. Accidental use-after-free due to JS implementation bugs is so rare that I wouldn't be surprised if it's never happened in practice.
- gpderetta 11y ago>It is untrue that typical JavaScript applications are vulnerable to anywhere near as many memory safety issues as C++ applications are. Even "modern C++". The OP was talking about JS runtimes and JITs.
- nickpsecurity 11y agoExactly. There's attacks on them posted quite regularly.
- pcwalton 11y agoNote the emphasis on accidental memory safety violations. There's an enormous difference between attackers running JavaScript that they control and attackers having to exploit memory safety issues in JavaScript that you wrote. Virtually all attacks against JavaScript JITs have been of the former type, in that they rely on perfectly crafted hostile JavaScript that nobody would write on purpose. But in a node.js type of server side scenario, attackers do not have the ability to run arbitrary JavaScript. They only have the ability to interact with the JavaScript that was already written to be non-malicious. So it's much, much harder for an attacker to exploit memory safety problems in the JS engine in a server side scenario—so much harder, in fact, that I wouldn't be surprised if it's never been done. If your argument is that JS JITs are hard to write, well, sure. But I think that's totally irrelevant to this conversation. Clang and LLVM are also hard to write and are just as trusted in this scenario.
- nickpsecurity 11y ago"Note the emphasis on accidental memory safety violations." Good points. Of course, I'm guessing you're saying it's still really hard to write memory-safe code with modern C++ constructs whereas others here suggest it's pretty easy. That point is tripping me up in these discussions. Did a quick Google on C++ safety and found you already said something about the topic: https://news.ycombinator.com/item?id=7587978 https://news.ycombinator.com/item?id=7587978 My statement is predicated on the premise that modern C++ can be done safely without issues like that. If not, then it's false and we're back to me recommending safer, systems languages. One thing to remember, though, is that there's tools to automatically transform C code into safe code. Softbound + CETS comes to mind. Might be able to use a C++-to-C compiler with one of those. There's also safer forms of C++ like Ironclad C++. http://www.cs.grinnell.edu/~osera/papers/ironclad-cc.pdf http://www.cs.grinnell.edu/~osera/papers/ironclad-cc.pdf So, the situation might be worse than people looking into C++ were hoping but not as bad as you think.