diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-04-20 18:52:03 +0100 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2019-04-20 16:41:02 -0400 |
commit | 20762ecb3c34493a6de637d37234d738467f69a9 (patch) | |
tree | 28b92fbcf8f9a24ecd76cb61aeae059973a68e3c /swaybar/tray | |
parent | swaynag: revamp type configs (diff) | |
download | sway-20762ecb3c34493a6de637d37234d738467f69a9.tar.gz sway-20762ecb3c34493a6de637d37234d738467f69a9.tar.zst sway-20762ecb3c34493a6de637d37234d738467f69a9.zip |
Validate icon_struct in read_theme_file
The read_theme_file function used to return an invalid icon_struct in
some cases, for example when an empty index.theme file was read.
This makes sure the struct we're returning is always valid as per the
Icon Theme specification.
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'swaybar/tray')
-rw-r--r-- | swaybar/tray/icon.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c index 56f230e1..c7e7f6bc 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/tray/icon.c | |||
@@ -82,6 +82,10 @@ static int cmp_group(const void *item, const void *cmp_to) { | |||
82 | return strcmp(item, cmp_to); | 82 | return strcmp(item, cmp_to); |
83 | } | 83 | } |
84 | 84 | ||
85 | static bool validate_icon_theme(struct icon_theme *theme) { | ||
86 | return theme && theme->name && theme->comment && theme->directories; | ||
87 | } | ||
88 | |||
85 | static bool group_handler(char *old_group, char *new_group, | 89 | static bool group_handler(char *old_group, char *new_group, |
86 | struct icon_theme *theme) { | 90 | struct icon_theme *theme) { |
87 | if (!old_group) { // first group must be "Icon Theme" | 91 | if (!old_group) { // first group must be "Icon Theme" |
@@ -89,7 +93,7 @@ static bool group_handler(char *old_group, char *new_group, | |||
89 | } | 93 | } |
90 | 94 | ||
91 | if (strcmp(old_group, "Icon Theme") == 0) { | 95 | if (strcmp(old_group, "Icon Theme") == 0) { |
92 | if (!(theme->name && theme->comment && theme->directories)) { | 96 | if (!validate_icon_theme(theme)) { |
93 | return true; | 97 | return true; |
94 | } | 98 | } |
95 | } else { | 99 | } else { |
@@ -276,7 +280,7 @@ static struct icon_theme *read_theme_file(char *basedir, char *theme_name) { | |||
276 | free(full_line); | 280 | free(full_line); |
277 | fclose(theme_file); | 281 | fclose(theme_file); |
278 | 282 | ||
279 | if (!error) { | 283 | if (!error && validate_icon_theme(theme)) { |
280 | theme->dir = strdup(theme_name); | 284 | theme->dir = strdup(theme_name); |
281 | return theme; | 285 | return theme; |
282 | } else { | 286 | } else { |