Syllo / nvtop

GPU & Accelerator process monitoring for AMD, Apple, Huawei, Intel, NVIDIA and Qualcomm
Other
7.95k stars 291 forks source link

Fix: handle empty `/proc/[PID]/cmdline` properly #104

Closed oToToT closed 3 years ago

oToToT commented 3 years ago

In some rare cases, the file /proc/[PID]/cmdline might be empty. This causes nvtop display wrong information about command being executed or even leak some data inside current memory.

For example, it might leak something similar to /etc/passwd. image

I'm not sure how htop or ps handle this kind of case, but I think it's OK to display nothing in command section as it's actually empty there.

oToToT commented 3 years ago

I'm not very sure that whether /proc/[PID]/cmdline will always contain '\0' in the end or not. Might it be much better to append a '\0' directly to the end of the buffer?

Syllo commented 3 years ago

Hi, Indeed, a zero character read can be returned for this file. Could you please check that the fix in the branch cmdline_fix resolves this issue?

oToToT commented 3 years ago

Hi, Indeed, a zero character read can be returned for this file. Could you please check that the fix in the branch cmdline_fix resolves this issue?

Yes, that patch do resolve this issue and I think it's a better fix than mine.

Syllo commented 3 years ago

Merged into master, you're welcome. Take care!