
Rust in an Instant - todsacerdoti
https://fnordig.de/2020/05/02/rust-in-an-instant/
======
pornel
People often mistake Rust's safety guarantees for a sandbox like JavaScript.
"Safe" Rust code is still on the trusted side of the airtight hatchway[1], so
hacks like that are a class of "arbitrary code execution leads to arbitrary
code execution".

[1]:
[https://devblogs.microsoft.com/oldnewthing/20060508-22/?p=31...](https://devblogs.microsoft.com/oldnewthing/20060508-22/?p=31283)

------
Gaelan
Wait, isn’t this a soundness issue? Couldn’t you, say, replace malloc with a
safe function that always returned 0x4 [0], causing segfaults with no unsafe?

[0]: chosen by fair dice roll

EDIT: yep, [https://github.com/rust-
lang/rust/issues/28179](https://github.com/rust-lang/rust/issues/28179)

~~~
ChrisSD
Calling platform functions are always unsafe. In the case of malloc, the
standard library wraps calls using a safe interface. This assumes that malloc
is implemented to spec because there's no good way to handle it otherwise.

------
cobbzilla
A better title would have been “How to Override Standard Library Functions in
Rust”.

~~~
layoutIfNeeded
Or: "Rust user discovers the linker"

~~~
Argorak
That's a really shitty comment. The author is a long term Rust contributor and
has spent their time before on C-land a lot. Yes, he knows how a linker works.
Others don't.

He took his time to write down something, because some beginners asked him on
Twitter.

Someone posts it on Hacker News and you shit over it like this.

If the post is too mundane for you, so be it. You're not the audience.

------
Matthias247
I this didn't lead to a "duplicate method definition" error by the linker. The
more typical way I know for mocking/intercepting OS functions is using the
-Wl,--wrap=clock_gettime linker flags [1] which allow to redirect calls to a
__wrap_clock_gettime functions. But that doesn't seem to have been necessary
here.

[1] [https://drewdevault.com/2016/07/19/Using-Wl-wrap-for-
mocking...](https://drewdevault.com/2016/07/19/Using-Wl-wrap-for-mocking-
in-C.html)

------
bitcharmer
I get that Rust is a promising language, but for the love of god, out of the
top ten articles on HN's main page 5 are about Rust.

Rust is not the only thing I come here for.

~~~
armSixtyFour
I remember reading it was everyone's favorite weekend language. There's
certainly more people using it over the weekend than using it professionally.
Maybe that's why there's so much of here today.

