Sqlite also has never had a severe CVE, from the parent's link:
> All historical vulnerabilities reported against SQLite require at least one of these preconditions:
> The attacker can submit and run arbitrary SQL statements.
> The attacker can submit a maliciously crafted database file to the application that the application will then open and query.
The OP's vulnerability requires passing an insanely long string to a C api, which isn't something you'd expect to be secure.
Here we are dealing with a memory safety problem of a type that cannot occur in Rust unless you use `unsafe` blocks. Rust doesn't allow unsafe memory access such as pointer arithmetic or out-of-bounds operations (those produce a runtime panic). C happily accepts those, and the effects may include buffer overflows leading to arbitrary code execution.
This should never, ever be possible when writing a normal program. I love that Rust has named the keyword that enables such things "unsafe", because that's precisely what it is. That C has this behavior as a default is nothing short of madness, though of course C is an artifact of a time when such issues weren't understood as well as they are today.
That being said, whether a runtime panic leads to DoS depends on the execution model. In web applications, threads are usually mapped to connections in some way, and a runtime panic only unwinds the thread it occurs in, so this wouldn't necessarily mean that other users experience service disruptions.
More to the point, I'd expect modern application and/or library code to include default safety checks that prevent scenarios like absurdly large queries from happening in the first place, and provide recoverable errors if such pathological inputs are encountered.
We have seen time and time again that humans aren't good enugh at that task, even in low-level code (and 2x is very buch an outlier).
You may as well be correct about not helping here, but borrow checker provides proofs, not tests; a test can only prove the presence of a bug, while a proof can prove the lack of a certain kind of bug.
1. Accepting user input on a webpage (e.g. a first_name field on a singup form)
2. Storing that user input in a database
Would trigger a RCE if the string was escaped properly.
https://www.sqlite.org/cves.html has a snippet about this, for example.
How do you do this in Firefox? Firefox never implemented WebSQL.
I don't think SQLite needs to be rewritten in any language, tho.
Yes it is!
Rust would help here - not the borrow checker, but the bounds checking.
(the Rust compiler is written in Rust, but the LLVM backend it uses (and soon GCC, IIRC), is still written in C++)
Though to actually get binaries out of it LLVM is used, which itself is written in C++.
Sure, write new stuff in Rust, but SQLite needs to stay in C at this point.
I would like them to try, though, because I suspect, barring a Bellard Event, no-one will be able to get close to SQLite's functionality[1], reliability, etc., in a new Rust implementation within 5 years (possibly even 10 years.)
[1] including being able to load extensions, integrate into basically everything as library, etc.
And again, SQLite is used in places that Rust has no compiler for. This is a hard constraint that precludes using Rust.
Just the other day I found a relatively recent C++ tutorial on YouTube using Turbo C++ for MS-DOS, imagine how idiomatic it looked like.
And most of those "teralines" of code are legacy garbage. The core OS, a basic userland, a database and a webserver are 90% of the world's critical IT infrastructure. That doesn't take a century to rewrite.
You will lose all of that in a rewrite, which is why people don't do it.
> You will lose all of that in a rewrite
I don't think you lose everything in a rewrite in general - you still have all of the edge cases and business logic in the old code that you translate to the new code. It's not like you are implementing whatever it is from scratch.
Sure, there are opportunities for the translation to introduce regressions, but that's a vastly different argument (and I think a much more minor downside).
At some point you have to come to terms with the fact that some bugs shouldn’t be fixed.
And you don't have to rewrite everything at once, you can do it at the function or file level bit by bit. Perhaps the parts that are changing the most are done first, or perhaps the parts with the most bugs.
I'm still not saying rewriting is always right or wrong, but I think it isn't as cut and dry as some make it sound.
Well I have this native app fetish. I mean why pay for 4 G ram for each electron app?
No, there is more legacy code than you list there.
Please keep those web apps.
(I'm actually curious, how does dynamic linking work with Rust? Can you build a .so/.dll/.h pair and ship it everywhere like with C?)
everywhere depends on what you mean; rustc does have support for fewer platforms than gcc. But it's still quite a few.
The people who think this is the solution are the ones who will need to take up the work.
It's not like the people who don't think this is the solution will do it.
Get ready to work hard for 5, 10, 20 years... rewriting sqlite will be a monumental effort and take the laser focus of a strong development team for years, if not decades. It's fraught with risk. Think about it... how many years would it be before a stable version of sqlite based on rust was available with comparable performance and fewer bugs than the c-based version?
(Seems likely to me that it would never happen.)
I think you'd be better off creating a sqlite competitor, that could start off much smaller with a much smaller feature and much less stringent performance requirements that, nevertheless, has enough for many common cases. Of course, you'd still have to convince people to use it over sqlite. If your main selling point is "significantly fewer bugs than sqlite" I don't think it's going to be very easy to make that true, rust or not.
I have the greatest respect for the quality of the SQLite codebase, which is one of the best-tested open source projects in existence, but at the end of the day, if formatting a string can lead to arbitrary code execution, it's time to question the foundations you're building on.
As long as C and C++ are considered acceptable languages for writing mission critical software, these vulnerabilities will never go away. We have incredible static analysis tools and hyper-advanced fuzzers driven by genetic algorithms, and yet this continues to happen despite every precaution imaginable being taken.
It's time to fix the problem at its root. Languages that are memory unsafe by default need to be phased out sooner rather than later.