←back to thread

517 points bkolobara | 7 comments | | HN request time: 0.905s | source | bottom
Show context
merdaverse ◴[] No.45043051[source]
Code written below your line gets executed if you don't return early. More breaking news at 8.

Seriously, why would you think that assigning a value would stop your script from executing? Maybe the Typescript example is missing some context, but it seems like such a weird case to present as a "data race".

replies(8): >>45043245 #>>45043339 #>>45043398 #>>45043537 #>>45043876 #>>45046033 #>>45046975 #>>45049155 #
lights0123 ◴[] No.45043339[source]
exit(), execve(), and friends do immediately stop execution—I could understand why you'd think a redirect would as well.
replies(4): >>45043409 #>>45043410 #>>45049020 #>>45049406 #
dvt ◴[] No.45043410[source]
The redirect is an assignment. In no language has a variable assignment ever stopped execution.
replies(6): >>45043422 #>>45043544 #>>45043663 #>>45043805 #>>45047504 #>>45047601 #
1. ordu ◴[] No.45043805[source]
Try this in C:

*(int*)0 = 0;

Modern C compilers could require you to complicate this enough to confuse them, because their approach to UB is weird, if they saw an UB they could do anything. But in olden days such an assignment led consistently to SIGSEGV and a program termination.

replies(1): >>45043955 #
2. DannyBee ◴[] No.45043955[source]
Unless you were on systems that mapped address 0 to a writable but always zero value so they could do load and store speculation without worry.

IBM did this for a long time

replies(3): >>45044327 #>>45045931 #>>45051939 #
3. ◴[] No.45044327[source]
4. mabster ◴[] No.45045931[source]
My favourite were older embedded systems where 0 was an address you actually do interact with. So for some portion of the code you WANT null pointer access. I can't remember the details but I do remember jumping to null to reset the system being pretty common.
replies(2): >>45046092 #>>45049285 #
5. marshray ◴[] No.45046092{3}[source]
Probably the system interrupt table. Index 0 might reference the handler for the non-maskable interrupt NMI, often the same as a power-on reset.

I recall that on DOS, Borland Turbo C would detect writes to address 0 and print a message during normal program exit.

6. ghurtado ◴[] No.45049285{3}[source]
RANDOMIZE USR 0
7. ncruces ◴[] No.45051939[source]
In Wasm you can read/write whatever to address zero of linear memory.

It's still UB as far as clang is concerned so you C code can do whatever. But it won't “crash” on the spot.