4 ms·
> It's terribly non-obvious how to deal with correctly. Like the post says: read the whole thing into memory and do a reverse search for the last ')', i.e. str
by st_goliath 4y ago
> It's terribly non-obvious how to deal with correctly.
Like the post says: read the whole thing into memory and do a reverse search for the last ')', i.e. strrchr
Once you are aware of the problem, it's obvious how to solve it, but I do agree that the hidden danger here is not immediately obvious at first.
- zokier 4y agoNote that man page says that the name is truncated to 16 chars, so if for whatever reason you don't want to do unbounded length read then you can use that
- jyxent 4y agoThey actually allow up to 64 characters in the kernel: https://github.com/torvalds/linux/blob/8395ae05cb5a2e31d36106e8c85efa11cda849be/fs/proc/array.c#L100 https://github.com/torvalds/linux/blob/8395ae05cb5a2e31d3610... This might just be for certain kernel things though. I don't see any regular processes that aren't truncated, but I see a bunch of kernel things that have more than 16 chars on my system.
- deleted 4y ago[deleted]