Remove all sprintf calls

Replace them with snprintf, which ensures buffer overflows won't
happen.
This commit is contained in:
Simon Ser 2022-02-08 09:52:24 +01:00 committed by Simon Zeni
parent ac7892371c
commit f707f583e1
4 changed files with 7 additions and 6 deletions

View file

@ -1706,7 +1706,7 @@ static void update_marks_texture(struct sway_container *con,
for (int i = 0; i < con->marks->length; ++i) {
char *mark = con->marks->items[i];
if (mark[0] != '_') {
sprintf(part, "[%s]", mark);
snprintf(part, len + 1, "[%s]", mark);
strcat(buffer, part);
}
}

View file

@ -209,7 +209,7 @@ static pid_t get_parent_pid(pid_t child) {
FILE *stat = NULL;
size_t buf_size = 0;
sprintf(file_name, "/proc/%d/stat", child);
snprintf(file_name, sizeof(file_name), "/proc/%d/stat", child);
if ((stat = fopen(file_name, "r"))) {
if (getline(&buffer, &buf_size, stat) != -1) {