unix/fiss

sprintf -> snprint for boundary checks (39e4016d97c4ee78180fd9d73d6fa44c9c365025)
Repositories | LICENSE

commit 39e4016d97c4ee78180fd9d73d6fa44c9c365025
parent 047a81cb0a227aa92370fdeaeefc074ac58f14e5
Author: Friedel Schon <[email protected]>
Date:   Tue, 25 Apr 2023 21:38:28 +0200

sprintf -> snprint for boundary checks

Diffstat:
Msrc/start.c6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/start.c b/src/start.c @@ -102,11 +102,11 @@ void service_start(service_t* s, bool* changed) { char path_buf[PATH_MAX]; struct stat estat; - if (sprintf(path_buf, "%s/%s/run", service_dir, s->name) && stat(path_buf, &estat) == 0 && estat.st_mode & S_IXUSR) { + if (snprintf(path_buf, PATH_MAX, "%s/%s/run", service_dir, s->name) && stat(path_buf, &estat) == 0 && estat.st_mode & S_IXUSR) { s->state = STATE_ACTIVE_FOREGROUND; - } else if (sprintf(path_buf, "%s/%s/start", service_dir, s->name) && stat(path_buf, &estat) == 0 && estat.st_mode & S_IXUSR) { + } else if (snprintf(path_buf, PATH_MAX, "%s/%s/start", service_dir, s->name) && stat(path_buf, &estat) == 0 && estat.st_mode & S_IXUSR) { s->state = STATE_STARTING; - } else if (sprintf(path_buf, "%s/%s/depends", service_dir, s->name) && stat(path_buf, &estat) == 0 && estat.st_mode & S_IREAD) { + } else if (snprintf(path_buf, PATH_MAX, "%s/%s/depends", service_dir, s->name) && stat(path_buf, &estat) == 0 && estat.st_mode & S_IREAD) { s->state = STATE_ACTIVE_DUMMY; } else { printf("error in %s: `run`, `start` or `depends` not found\n", s->name);