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:
Antonin Décimo 2020-06-04 13:47:57 +02:00 committed by Tudor Brindus
parent 8033b575f7
commit 2960b2c9b6

View file

@ -24,6 +24,9 @@ static char *hex_to_rgba_hex(const char *hex) {
return NULL; return NULL;
} }
char *rgba = malloc(10); char *rgba = malloc(10);
if (!rgba) {
return NULL;
}
snprintf(rgba, 10, "#%08x", color); snprintf(rgba, 10, "#%08x", color);
return rgba; return rgba;
} }
@ -36,7 +39,7 @@ static struct cmd_results *parse_single_color(char **color,
} }
char *rgba = hex_to_rgba_hex(argv[0]); char *rgba = hex_to_rgba_hex(argv[0]);
if (!*rgba) { if (!rgba) {
return cmd_results_new(CMD_INVALID, "Invalid color: %s", argv[0]); return cmd_results_new(CMD_INVALID, "Invalid color: %s", argv[0]);
} }