diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2016-12-29 19:42:41 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2016-12-29 19:42:41 +0100 |
commit | 2b5c1b4b133a97a46354142aa8ab0d9e79bc70a4 (patch) | |
tree | 208946c62eff13e9e6654a146cf8ff38ea7796b1 /Process.c | |
parent | 8af4d9f453ffa2209e486418811f7652822951c6 (diff) |
Replace all uses of sprintf with snprintf
In all the cases where sprintf was being used within htop, snprintf
could have been used. This patch replaces all uses of sprintf with
snprintf which makes sure that if a buffer is too small to hold the
resulting string, the string is simply cut short instead of causing
a buffer overflow which leads to undefined behaviour.
`sizeof(variable)` was used in these cases, as opposed to `sizeof
variable` which is my personal preference because `sizeof(variable)`
was already used in one way or another in other parts of the code.
Diffstat (limited to 'Process.c')
-rw-r--r-- | Process.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -198,7 +198,7 @@ void Process_setupColumnWidths() { snprintf(Process_titleBuffer[i], 20, "%*s ", digits, Process_pidColumns[i].label); Process_fields[Process_pidColumns[i].id].title = Process_titleBuffer[i]; } - sprintf(Process_pidFormat, "%%%dd ", digits); + snprintf(Process_pidFormat, sizeof(Process_pidFormat), "%%%dd ", digits); } void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { |