Get the latest tech news

C stdlib isn't threadsafe and even safe Rust didn't save us


Threads, TLS, a C stdlib race, and Rust: how EdgeDB hit a hidden landmine.

Reading the disassembly, and cross-referencing it with the C code, we determined that the register x20 corresponded with the variable ep, the pointer used to walk through the environ array. The code seemed to expect x20 to be changing, and it was the clearest candidate to be the register representing ep, but it didn’t appear on the left hand side of any instruction. Because this crash is caused by a memory-moving realloc, triggered by setenv which happens at the same time another thread is calling getenv, it requires a lot of pieces to fall into the right place.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of safe rust

safe rust

Photo of C stdlib

C stdlib

Related news:

News photo

New System Auto-Converts C To Memory-Safe Rust, But There's a Catch

News photo

Compiling C to Safe Rust, Formalized