diff options
author | Simon Ser <contact@emersion.fr> | 2022-02-08 09:52:24 +0100 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-02-08 09:20:13 -0500 |
commit | f707f583e17cb5e8323ceb4bfd951ad0465b7d10 (patch) | |
tree | 9de2eaecf63cb4f8e1c0af7ba1c7c9d7a8fd01a4 /swaynag/swaynag.c | |
parent | Fix snprintf compiler warning (diff) | |
download | sway-f707f583e17cb5e8323ceb4bfd951ad0465b7d10.tar.gz sway-f707f583e17cb5e8323ceb4bfd951ad0465b7d10.tar.zst sway-f707f583e17cb5e8323ceb4bfd951ad0465b7d10.zip |
Remove all sprintf calls
Replace them with snprintf, which ensures buffer overflows won't
happen.
Diffstat (limited to 'swaynag/swaynag.c')
-rw-r--r-- | swaynag/swaynag.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 03ec0411..23d23f38 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c | |||
@@ -28,8 +28,9 @@ static bool terminal_execute(char *terminal, char *command) { | |||
28 | fprintf(tmp, "#!/bin/sh\nrm %s\n%s", fname, command); | 28 | fprintf(tmp, "#!/bin/sh\nrm %s\n%s", fname, command); |
29 | fclose(tmp); | 29 | fclose(tmp); |
30 | chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR); | 30 | chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR); |
31 | char *cmd = malloc(sizeof(char) * (strlen(terminal) + strlen(" -e ") + strlen(fname) + 1)); | 31 | size_t cmd_size = strlen(terminal) + strlen(" -e ") + strlen(fname) + 1; |
32 | sprintf(cmd, "%s -e %s", terminal, fname); | 32 | char *cmd = malloc(cmd_size); |
33 | snprintf(cmd, cmd_size, "%s -e %s", terminal, fname); | ||
33 | execlp("sh", "sh", "-c", cmd, NULL); | 34 | execlp("sh", "sh", "-c", cmd, NULL); |
34 | sway_log_errno(SWAY_ERROR, "Failed to run command, execlp() returned."); | 35 | sway_log_errno(SWAY_ERROR, "Failed to run command, execlp() returned."); |
35 | free(cmd); | 36 | free(cmd); |