5 ms·
Go is just memory safe until you have a race, or so I have heard.
by sigg3 4y ago
Go is just memory safe until you have a race, or so I have heard.
- pclmulqdq 4y agoThe same goes for Rust and most other "safe" languages. They all have synchronization primitives that make it safe, but you need to use them - the compiler won't always tell you.
- suremarc 4y agoI have no idea what you mean here. Data races are next to impossible in safe Rust.
- Dobbs 4y agoThat is basically the entire shtick of rust. That data is "owned", and only the owner can write. You can "borrow" something for read access, but if something is borrowed it can't be written to. There are of course workarounds for this like reference counted wrappers and so on.
- bilkow 4y agoFor Rust specifically, the compiler does force safe programs to have no data races. That's actually what the ownership system, Send and Sync are about. If you manage to corrupt memory or have undefined behavior in safe Rust, that should be a compiler or library bug. See https://doc.rust-lang.org/nomicon/races.html https://doc.rust-lang.org/nomicon/races.html
- suremarc 4y agoIndeed, this person showed that you can read/write to arbitrary memory addresses inside of a Go program: https://blog.stalkr.net/2022/01/universal-go-exploit-using-data-races.html https://blog.stalkr.net/2022/01/universal-go-exploit-using-d... Although, it's pretty useless as an exploit, since it requires you to be able to run arbitrary Go code to begin with (the author admits as much). It's _very_ unlikely that a remote attacker could exploit a data race in a regular Go program.
- Thaxll 4y agoEvery GC language by definition are memory safe, memory safety in programming does not mean than accessing the same resources from two thread should be safe.
- suremarc 4y agoI don't know how it works in other languages, but accessing a partially overwritten slice in Go (as will happen in the presence of data races) can cause your code to access out-of-bounds memory. And as we all know, once you have read/write access to arbitrary areas in memory, you've basically opened up Pandora's box.
- Thaxll 4y agoGo is memory safe, if not then Java/C#/Python/Ruby are not either.
- suremarc 4y agoI don't think you can have data races (but certainly you can have race conditions) in python because of the GIL. I imagine Ruby is similar. Otherwise, no, the other languages you listed are not "memory safe". Once you start reading and writing to arbitrary locations in a process, almost anything can happen. But certainly you can say that there are different degrees of memory safety. All of the languages you mentioned are leaps and bounds above C/C++.