Crust of Rust: Smart Pointers and Interior Mutability
Video Statistics and Information
Channel: Jon Gjengset
Views: 45,637
Rating: 4.969543 out of 5
Keywords: rust, live-coding, mutability, cell, refcell, smart pointers, rc
Id: 8O0Nt9qY_vo
Channel Id: undefined
Length: 123min 4sec (7384 seconds)
Published: Wed Jun 17 2020
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
At one point he struggles to demonstrate why a program with UB is actually UB (the memory is free'd but isn't re-used, so printing the previous values still works). This is the whole point about why UB is bad: the program works fine until you change some code somewhere else, then suddenly you get a segfault. Or worse, even though the program works fine normally, an attacker could craft program input to let him/her to jump into shellcode.
Same with the `unsafe Sync`: if setting a value requires multiple steps, possibly including allocating memory for example, and the 2 threads randomly interleve their commands sometimes, then most of the time everything will be fine, but occasionally the data will be corrupted. Again, if an attacker can control timing he/she might be able to again jump into their own shellcode.
It's good that he struggles to show these problems, because it highlights the fact that they are intermittent and often hidden, and therefore often missed by normal debugging practices.
I'm enjoing the video, in case that isn't clear. :)
There goes my morning, love these videos!
After 30min I realised that I should code this myself with the video on the side. Thanks for doing these!
Thank you for making these videos. I've watched the first 3 Crust of Rust videos and they were very helpful and thorough. The length is just right and they all focus on very practical issues. I'll watch this one too, for sure. Interior Mutability is another concept that I was hoping to figure out at some point and never got around to it.
The previous kind of videos you made were slightly too advanced and intimidating for me. That said, I'm sure they're great. As I become more proficient I will try watching them again.
Thanks Jon! I really like this videos.
This guy knows his stuff
Its amazing, this guy types faster than my brain processes what he is typing or saying. Great content though, bookmarked for when I feel brave enough.
This is a good video but I have a small request for you to re-read the questions you are reading off-camera before answering them. It's a little tricky to understand what you are answering context-free.
Many thanks!
If a pointer is immutable, than of course it can't be changed itself, but i think dereferencing it and changing the value is only natural. I've never declared the heap-allocated struct to be immutable, only the pointer.
This works in C, and i think in rust it works the same way. The pointer itself doesn't change, like
0xoFF1DE4
or something like that remains permanent, but the data it's pointing to is changeable.