Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Or Scanf Isn'T
Re: [patch] proc.5: tell how to parse /proc/*/stat correctly
oss-sec mailing list archives From: Dominique Martinet <asmadeus () codewreck org> Date: Fri, 23 Dec 2022 09:15:45 +0900 Solar Designer wrote on Fri, Dec 23, 2022 at 12:21:12AM +0100: Ah, this came just after the /proc/net/unix discussion in another thread[1] pointing to [2] with one line per entry, and I was still in that mode.
Re: [patch] proc.5: tell how to parse /proc/*/stat correctly
oss-sec mailing list archives From: Jan Engelhardt <jengelh () inai de> Date: Fri, 23 Dec 2022 01:21:42 +0100 (CET) On Thursday 2022-12-22 23:03, Dominique Martinet wrote: strrchr does not concern itself with "lines". If your input buffer contains the complete content of /proc/X/stat (and not just a "line" thereof), the strrchr approach appears quite workable.
Re: [patch] proc.5: tell how to parse /proc/*/stat correctly
oss-sec mailing list archives From: Solar Designer <solar () openwall com> Date: Fri, 23 Dec 2022 00:21:12 +0100 On Fri, Dec 23, 2022 at 07:03:17AM +0900, Dominique Martinet wrote: No, just don't treat this file's content as a line (nor as several lines) - treat it as a string that might contain new line characters. The ps command from procps-ng seems to manage, e.g. for your test "ps c" prints: 29394 pts/3 S 0:00 test) 0 0 0?
Re: [patch] proc.5: tell how to parse /proc/*/stat correctly
oss-sec mailing list archives From: Dominique Martinet <asmadeus () codewreck org> Date: Fri, 23 Dec 2022 07:03:17 +0900 Alexey Dobriyan wrote on Thu, Dec 22, 2022 at 07:42:53PM +0300: That's still not enough unless new lines are escaped, which they aren't: $ echo -n 'test) 0 0 0 ' > /proc/$$/comm $ cat /proc/$$/stat 71076 (test) 0 0 0 ) S 71075 71076 71076 34840 71192 4194304 6623 6824 0 0 10 3 2 7 20 0 1 0 36396573 15208448 2888 18446744073709551615 94173281726464 94173282650929...
[patch] proc.5: tell how to parse /proc/*/stat correctly
oss-sec mailing list archives From: Alexey Dobriyan <adobriyan () gmail com> Date: Thu, 22 Dec 2022 19:42:53 +0300 /proc/*/stat can't be parsed with split() or split(" ") or split(' ') or sscanf("%d (%s) ...") or equivalents because "comm" can contain whitespace and parenthesis and is not escaped by the kernel. BTW escaping would not help with naive split() anyway. Mention strrchr(')') so people can at least stop adding new bugs.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Or Scanf
Contact Or Scanf, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack