aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-15 17:55:27 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-12-15 17:55:27 +0000
commit0d6b5f522ed755aca8a85c005962fb03232b4c96 (patch)
treeac866711302bb71827f5f5b1c8ab439b8a4c0ecc
parentcsi: SGR 21 is “double underline”, not “disable bold” (according to ECMA-48) (diff)
config_font_parse(): return fail/success
-rw-r--r--CHANGELOG.md1
-rw-r--r--config.c34
-rw-r--r--config.h2
-rw-r--r--main.c9
4 files changed, 35 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa15a4c9..9569c3e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -136,6 +136,7 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See
(e.g. `\E[38:5...m`)
* Frames occasionally being rendered while application synchronized
updates is in effect.
+* Handling of failures to parse the font specification string.
### Security
diff --git a/config.c b/config.c
index 085c9f7e..7434896a 100644
--- a/config.c
+++ b/config.c
@@ -534,8 +534,16 @@ parse_section_main(const char *key, const char *value, struct config *conf,
/* Trim spaces, strictly speaking not necessary, but looks nice :) */
while (*font != '\0' && isspace(*font))
font++;
- if (*font != '\0')
- tll_push_back(conf->fonts[idx], config_font_parse(font));
+ if (*font != '\0') {
+ struct config_font font_data;
+ if (!config_font_parse(font, &font_data)) {
+ LOG_ERR("%s:%d: [default]: %s: invalid font specification",
+ path, lineno, key);
+ free(copy);
+ return false;
+ }
+ tll_push_back(conf->fonts[idx], font_data);
+ }
}
free(copy);
}
@@ -2083,8 +2091,14 @@ config_load(struct config *conf, const char *conf_path,
conf->colors.selection_bg >> 24 == 0;
out:
- if (ret && tll_length(conf->fonts[0]) == 0)
- tll_push_back(conf->fonts[0], config_font_parse("monospace"));
+ if (ret && tll_length(conf->fonts[0]) == 0) {
+ struct config_font font;
+ if (!config_font_parse("monospace", &font)) {
+ LOG_ERR("failed to load font 'monospace' - no fonts installed?");
+ ret = false;
+ } else
+ tll_push_back(conf->fonts[0], font);
+ }
free(conf_file.path);
if (conf_file.fd >= 0)
@@ -2131,10 +2145,12 @@ config_free(struct config conf)
user_notifications_free(&conf.notifications);
}
-struct config_font
-config_font_parse(const char *pattern)
+bool
+config_font_parse(const char *pattern, struct config_font *font)
{
FcPattern *pat = FcNameParse((const FcChar8 *)pattern);
+ if (pat == NULL)
+ return false;
double pt_size = -1.0;
FcPatternGetDouble(pat, FC_SIZE, 0, &pt_size);
@@ -2150,10 +2166,12 @@ config_font_parse(const char *pattern)
char *stripped_pattern = (char *)FcNameUnparse(pat);
FcPatternDestroy(pat);
- return (struct config_font){
+ *font = (struct config_font){
.pattern = stripped_pattern,
.pt_size = pt_size,
- .px_size = px_size};
+ .px_size = px_size
+ };
+ return true;
}
void
diff --git a/config.h b/config.h
index 9e5e8b4e..57af908e 100644
--- a/config.h
+++ b/config.h
@@ -191,5 +191,5 @@ bool config_load(
user_notifications_t *initial_user_notifications, bool errors_are_fatal);
void config_free(struct config conf);
-struct config_font config_font_parse(const char *pattern);
+bool config_font_parse(const char *pattern, struct config_font *font);
void config_font_destroy(struct config_font *font);
diff --git a/main.c b/main.c
index 59ac9b61..094c242a 100644
--- a/main.c
+++ b/main.c
@@ -403,8 +403,13 @@ main(int argc, char *const *argv)
config_font_destroy(&it->item);
tll_free(conf.fonts[i]);
}
- tll_foreach(conf_fonts, it)
- tll_push_back(conf.fonts[0], config_font_parse(it->item));
+ tll_foreach(conf_fonts, it) {
+ struct config_font font;
+ if (!config_font_parse(it->item, &font)) {
+ LOG_ERR("%s: invalid font specification", it->item);
+ } else
+ tll_push_back(conf.fonts[0], font);
+ }
tll_free(conf_fonts);
}
if (conf_width > 0 && conf_height > 0) {