summaryrefslogtreecommitdiffstats
path: root/TraceScreen.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2016-12-29 19:42:41 +0100
committerTomasz Kramkowski <tk@the-tk.com>2016-12-29 19:42:41 +0100
commit2b5c1b4b133a97a46354142aa8ab0d9e79bc70a4 (patch)
tree208946c62eff13e9e6654a146cf8ff38ea7796b1 /TraceScreen.c
parent8af4d9f453ffa2209e486418811f7652822951c6 (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 'TraceScreen.c')
-rw-r--r--TraceScreen.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/TraceScreen.c b/TraceScreen.c
index 2d6eb336..bd771182 100644
--- a/TraceScreen.c
+++ b/TraceScreen.c
@@ -99,7 +99,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
dup2(this->fdpair[1], STDERR_FILENO);
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
if (ok != -1) {
- sprintf(buffer, "%d", this->super.process->pid);
+ snprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
execlp("strace", "strace", "-p", buffer, NULL);
}
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";

© 2014-2024 Faster IT GmbH | imprint | privacy policy