top | item 47176871

(no title)

fulafel | 2 days ago

They're more like capabilities or handles than pointers. There's a reason in Rust land many systems use handles (indices to a table of objects) in absence of pointer arithmetic.

In the C API of course there's symbolic names for these. STDIN_FILENO, STDOUT_FILENO, etc for the defaults and variables for the dynamically assigned ones.

discuss

order

minitech|2 days ago

What they point to are capabilities, but the integer handles that user space gets are annoyingly like pointers. In some respects, better, since we don’t do arithmetic on them, but in others, worse: they’re not randomized, and I’ve never come across a sanitizer (in the ASan sense) for them, so they’re vulnerable to worse race condition and use-after-free issues where data can be quietly sent to the entirely wrong place. Unlike raw pointers’ issues, this can’t even be solved at a language level. And maybe worst of all, there’s no bug locality: you can accidentally close the descriptor backing a `FILE*` just by passing the wrong small integer to `close` in an unrelated part of the program, and then it’ll get swapped out at the earliest opportunity.

eichin|2 days ago

BITD the one "fd sanitizer" I ever encountered was "try using the code on VxWorks" which at the time was "posix inspired" at best - fds actually were pointers, so effectively random and not small integers. It didn't catch enough things to be worth the trouble, but it did clean up some network code (ISTR I was working on SNTP and Kerberos v4 and Kerberized FTP when I ran into this...)

1718627440|2 days ago

Handles and pointers are the same concept, the difference is just who resolves them. Pointers don't represent hardware addresses either.

fulafel|1 day ago

Well, if we reduce it enough I supposed they can be seen as the same concept through a certain kind of philosophical lense. True and false also belong in the same class, they're handles to a pool of two possible boolean values.

The difference is in scope. Pointers (aka memory addresses) are an ordered set of numbers enumerating all the memory locations, it enables unique powerful properties that enable a large set of uses that you cannot do with handles. And also make them quite unsafe and harder to understand.