diff options
author | Antonin Décimo <antonin.decimo@gmail.com> | 2020-06-04 13:47:57 +0200 |
---|---|---|
committer | Tudor Brindus <me@tbrindus.ca> | 2020-07-30 22:02:42 -0400 |
commit | 2960b2c9b6c77d42f2696c1997bda965594e5dd4 (patch) | |
tree | a632604bbd3ba626d086fd88613d646354d21dae | |
parent | ipc: fix aligment issue of data buffer (diff) | |
download | sway-2960b2c9b6c77d42f2696c1997bda965594e5dd4.tar.gz sway-2960b2c9b6c77d42f2696c1997bda965594e5dd4.tar.zst sway-2960b2c9b6c77d42f2696c1997bda965594e5dd4.zip |
cmd/bar/colors: fix dereference of null pointer
`!*rgba` tests if the first byte of rgba isn't `'\0'`.
`hex_to_rgba_hex` returns NULL if `parse_color` fails. There's a null
pointer dereference in that case. The intended behavior is `!rgba`.
-rw-r--r-- | sway/commands/bar/colors.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c index ea2b912d..2d5b22bf 100644 --- a/sway/commands/bar/colors.c +++ b/sway/commands/bar/colors.c | |||
@@ -24,6 +24,9 @@ static char *hex_to_rgba_hex(const char *hex) { | |||
24 | return NULL; | 24 | return NULL; |
25 | } | 25 | } |
26 | char *rgba = malloc(10); | 26 | char *rgba = malloc(10); |
27 | if (!rgba) { | ||
28 | return NULL; | ||
29 | } | ||
27 | snprintf(rgba, 10, "#%08x", color); | 30 | snprintf(rgba, 10, "#%08x", color); |
28 | return rgba; | 31 | return rgba; |
29 | } | 32 | } |
@@ -36,7 +39,7 @@ static struct cmd_results *parse_single_color(char **color, | |||
36 | } | 39 | } |
37 | 40 | ||
38 | char *rgba = hex_to_rgba_hex(argv[0]); | 41 | char *rgba = hex_to_rgba_hex(argv[0]); |
39 | if (!*rgba) { | 42 | if (!rgba) { |
40 | return cmd_results_new(CMD_INVALID, "Invalid color: %s", argv[0]); | 43 | return cmd_results_new(CMD_INVALID, "Invalid color: %s", argv[0]); |
41 | } | 44 | } |
42 | 45 | ||