diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-02-05 14:13:27 -0500 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2019-02-05 14:13:27 -0500 |
commit | 89afb761ba21926b710b9e3d12361c3922d2baec (patch) | |
tree | 1f073eead802b2db385f1986373dcabd1171a00e /common | |
parent | 09c2a46b3d28b447ec070f0d6a57bd47fe1e6fd7 (diff) |
output_cmd_background: fix no file + valid mode
If output_cmd_background is given a valid mode as the first argument,
then there is no file given and an error should be returned.
join_args should not be called with an argc of zero since it sets the
last character to the null terminator. With an argc of zero, the length
is zero causing a heap buffer overflow when setting the byte before the
start of argv to '\0'. This probably will not ever generate a segfault,
but may cause data corruption to whatever is directly before it in
memory. To make other such cases easier to detect, this also adds a
sway_assert in join_args when argc is zero.
Diffstat (limited to 'common')
-rw-r--r-- | common/stringop.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/common/stringop.c b/common/stringop.c index 8af0d60f..709be684 100644 --- a/common/stringop.c +++ b/common/stringop.c @@ -258,6 +258,9 @@ int unescape_string(char *string) { } char *join_args(char **argv, int argc) { + if (!sway_assert(argc > 0, "argc should be positive")) { + return NULL; + } int len = 0, i; for (i = 0; i < argc; ++i) { len += strlen(argv[i]) + 1; |