Hacker News new | ask | show | jobs
by e-dant 83 days ago
This is cool stuff, but a nitpick: It’s not undefined behavior in the language sense in C to do socket ops on a bad file descriptor. It’s just an error from the kernel’s point of view, and the kernel will throw -errno at you.
2 comments

Yes it's not UB, but the consequences are not limited to a EINVAL/EBADF/EBADFD. Calling close twice is essentially the same problem as calling free twice, so you get all the use-after-free problems on your file descriptors.
Fair point! Updated. I’m definitely coming at this more from a Lean 4/formal methods perspective than a POSIX one.