diff options
-rw-r--r-- | sway/commands/output/background.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 5a15ed0f..054fb707 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -20,6 +20,16 @@ static const char *bg_options[] = { | |||
20 | "tile", | 20 | "tile", |
21 | }; | 21 | }; |
22 | 22 | ||
23 | static bool validate_color(const char *color) { | ||
24 | if (strlen(color) != 7 || color[0] != '#') { | ||
25 | return false; | ||
26 | } | ||
27 | |||
28 | char *ptr = NULL; | ||
29 | strtol(&color[1], &ptr, 16); | ||
30 | return *ptr == '\0'; | ||
31 | } | ||
32 | |||
23 | struct cmd_results *output_cmd_background(int argc, char **argv) { | 33 | struct cmd_results *output_cmd_background(int argc, char **argv) { |
24 | if (!config->handler_context.output_config) { | 34 | if (!config->handler_context.output_config) { |
25 | return cmd_results_new(CMD_FAILURE, "Missing output config"); | 35 | return cmd_results_new(CMD_FAILURE, "Missing output config"); |
@@ -36,6 +46,10 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
36 | struct output_config *output = config->handler_context.output_config; | 46 | struct output_config *output = config->handler_context.output_config; |
37 | 47 | ||
38 | if (strcasecmp(argv[1], "solid_color") == 0) { | 48 | if (strcasecmp(argv[1], "solid_color") == 0) { |
49 | if (!validate_color(argv[0])) { | ||
50 | return cmd_results_new(CMD_INVALID, | ||
51 | "Colors should be of the form #RRGGBB"); | ||
52 | } | ||
39 | output->background = strdup(argv[0]); | 53 | output->background = strdup(argv[0]); |
40 | output->background_option = strdup("solid_color"); | 54 | output->background_option = strdup("solid_color"); |
41 | output->background_fallback = NULL; | 55 | output->background_fallback = NULL; |
@@ -130,6 +144,11 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
130 | 144 | ||
131 | output->background_fallback = NULL; | 145 | output->background_fallback = NULL; |
132 | if (argc && *argv[0] == '#') { | 146 | if (argc && *argv[0] == '#') { |
147 | if (!validate_color(argv[0])) { | ||
148 | return cmd_results_new(CMD_INVALID, | ||
149 | "fallback color should be of the form #RRGGBB"); | ||
150 | } | ||
151 | |||
133 | output->background_fallback = strdup(argv[0]); | 152 | output->background_fallback = strdup(argv[0]); |
134 | argc--; argv++; | 153 | argc--; argv++; |
135 | 154 | ||