News for hackers. Stuff that matters.
Re:Google Announces KataOS and Sparrow by tannhaeuser on Sunday October 16, 2022 @09:23AM (#33223426)
> Rust [...] eliminates entire classes of bugs, such as off-by-one errors [...].

How so? OBO is a logic error isn't it?

Re:Google Announces KataOS and Sparrow by pas on Sunday October 16, 2022 @09:43AM (#33223567)
Iterators all the way down, maybe some const generics, who knows? :)
Re:Google Announces KataOS and Sparrow by eldenring on Sunday October 16, 2022 @11:15AM (#33224201)
Not 100% sure what they mean, but a lot of the api choices really try to make indexing decisions explicit.

ex: Bounds::Excluded

and iterators like the other commenter mentioned.

Re:Google Announces KataOS and Sparrow by efficax on Sunday October 16, 2022 @11:17AM (#33224219)
Rust gaurantees (except in unsafe code) that off-by-one errors will never lead to reading or writing from outside of safe memory bounds. You can still call `unwrap` on a out-of-bounds vector index and get a panic (panics are considered safe since they are memory safe), although you should not be using unwrap in ways that can panic in production code.
Re:Google Announces KataOS and Sparrow by atty on Sunday October 16, 2022 @12:09PM (#33224691)
It can’t stop me from accessing index 1 when I meant 0 on a 3d array, so I think the claim doesn’t make much sense. Rust can stop me from accessing index N+1 though, which is useful for security. Of course almost every language also has support for bounds checked arrays either in their core or their standard library, and some for of array iterators, so I don’t think that’s a particularly compelling reason to choose Rust.
Re:Google Announces KataOS and Sparrow by cmeacham98 on Sunday October 16, 2022 @03:08PM (#33226294)
What are the bounds checked arrays in C's or C++'s standard library?
Re:Google Announces KataOS and Sparrow by haolez on Sunday October 16, 2022 @03:32PM (#33226505)
You can enable bound checking when calling the compiler. I don't remember the actual command line flags, though.
Re:Google Announces KataOS and Sparrow by cmeacham98 on Sunday October 16, 2022 @05:01PM (#33227155)
A non-standard compiler feature is not "their core or their standard library".
Re:Google Announces KataOS and Sparrow by pjmlp on Sunday October 16, 2022 @06:14PM (#33227638)
The ISO standard requires at() to be checked, while it leaves for implementations the freedom to decide if operator[]() is checked or not.

As such, checks for operator[]() are usually only enabled in debug builds, although Android and Red-Hat ship with them enabled into production.

Additionally, before C++ got a standard library, the frameworks that were shipped alongside compilers always had those checks enabled by default.

Re:Google Announces KataOS and Sparrow by cmeacham98 on Sunday October 16, 2022 @11:12PM (#33229495)
I'll admit I don't have the stats in front of me, but I can practically for guarantee code using std::vector in the wild that [] usage outnumbers .at() usage, probably at least 10 (or even 100) to 1.

C also doesn't have .at(). Considering C and C++ are the most obvious and direct competitors to Rust, bounds checking would be a significant upgrade if Rust paradigms cause it to be used more often.

Re:Google Announces KataOS and Sparrow by pjmlp on Monday October 17, 2022 @01:41AM (#33230097)
It does, but as I mentioned, Red-Hat and Android ship with bounds checking enabled via FORTIFY.

C was already a bad option in the mid-90's compared with the alternatives, it is due to the unfortunate adoption of GNU manifesto and POSIX systems that we got where we are.

Re:Google Announces KataOS and Sparrow by cmeacham98 on Monday October 17, 2022 @03:42AM (#33230773)
> It does, but as I mentioned, Red-Hat and Android ship with bounds checking enabled via FORTIFY.

I was under the impression FORTIFY only checked bounds with specific functions (mostly those starting with "mem" or "str"), and not on general pointer arithmetic. Thus, an OOB array access would not be caught. Am I wrong on this? Online sources seem to agree with my understanding: https://zatoichi-engineer.github.io/2017/10/06/fortify-sourc...

Additionally, FORTIFY does not work on variable length arrays (like std::vector), only those which have a size known at compile time.

> Hence why the ultimate solution is to have hardware memory tagging for bounds checking, Solaris has been doing it for a decade, ARM is following along, including a collaboration with CHERI, only Intel borked their MPX design, and it seems not to be on RISC-V's radar.

Unfortunately, Intel and ARM are the only relevant vendors here (at least in 2022, but for the record I wish the others the best of luck), so Intel's implementation sucking is a huge blow.

Re:Google Announces KataOS and Sparrow by pjmlp on Monday October 17, 2022 @05:19AM (#33231344)
> Additionally, FORTIFY does not work on variable length arrays (like std::vector), only those which have a size known at compile time.

You use it alongside other compiler flags to enable them like _GLIBCXX_DEBUG, and FORTIFY levels.

It is not perfect, but since there are domains that won't stop using C and C++ past our lifetimes, that is better than nothing.

Re:Google Announces KataOS and Sparrow by cmeacham98 on Monday October 17, 2022 @10:32AM (#33234012)
The point being made, if we scroll way back up this thread, is that Rust (supposedly, I have maybe 30 mins of experience with it) has these protections built into the language, and doesn't require compiler flags with "DEBUG" in their name to get them.

If this is true, for new projects, such as the experimental OS we're all talking about, Rust (or any language with a similar feature) could be a better choice.

Re:Google Announces KataOS and Sparrow by ablatner on Wednesday October 19, 2022 @12:22AM (#33257620)
std::vector, with dynamic memory allocation, is not necessarily safe for embedded applications. It seems like Rust provides bounds checks at a primitive level.