oss-sec mailing list archives
Re: [patch] proc.5: tell how to parse /proc/*/stat correctly
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:
+ +Note that \fIcomm\fP can contain space and closing parenthesis characters. +Parsing /proc/${pid}/stat with split() or equivalent, or scanf(3) isn't +reliable. The correct way is to locate closing parenthesis with strrchr(')') +from the end of the buffer and parse integers from there.That's still not enough unless new lines are escaped, which they aren't:
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.
Current thread:
- [patch] proc.5: tell how to parse /proc/*/stat correctly Alexey Dobriyan (Dec 22)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Dominique Martinet (Dec 22)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Solar Designer (Dec 22)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Dominique Martinet (Dec 22)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Jan Engelhardt (Dec 22)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Lyndon Nerenberg (VE7TFX/VE6BBM) (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Shawn Webb (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Shawn Webb (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Demi Marie Obenour (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Jan Engelhardt (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Shawn Webb (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Demi Marie Obenour (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly John Helmert III (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Shawn Webb (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Alejandro Colomar (Dec 28)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Solar Designer (Dec 22)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Dominique Martinet (Dec 22)