mirror of
https://github.com/NickHu/sway
synced 2024-12-27 21:58:11 +01:00
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`.
This commit is contained in:
parent
8033b575f7
commit
2960b2c9b6
1 changed files with 4 additions and 1 deletions
|
@ -24,6 +24,9 @@ static char *hex_to_rgba_hex(const char *hex) {
|
|||
return NULL;
|
||||
}
|
||||
char *rgba = malloc(10);
|
||||
if (!rgba) {
|
||||
return NULL;
|
||||
}
|
||||
snprintf(rgba, 10, "#%08x", color);
|
||||
return rgba;
|
||||
}
|
||||
|
@ -36,7 +39,7 @@ static struct cmd_results *parse_single_color(char **color,
|
|||
}
|
||||
|
||||
char *rgba = hex_to_rgba_hex(argv[0]);
|
||||
if (!*rgba) {
|
||||
if (!rgba) {
|
||||
return cmd_results_new(CMD_INVALID, "Invalid color: %s", argv[0]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue