From 5c4ae642f2f5ce5bc78deed40a87315f01068bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 25 May 2021 17:34:09 +0200 Subject: [PATCH] =?UTF-8?q?tag:=20fix=20crash=20on=20empty=20tag=20specifi?= =?UTF-8?q?er,=20=E2=80=9C{}=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For strings with empty tag specifiers, “{}”, we ended up calling tag_for_name() with a NULL pointer for name. This caused us to crash. Closes #48 --- CHANGELOG.md | 2 ++ tag.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a02a7ba..c36baa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ (https://codeberg.org/dnkl/yambar/issues/32). * Crash in the `ramp` particle when the tag’s value was out-of-bounds (https://codeberg.org/dnkl/yambar/issues/45). +* Crash when a string particle contained `{}` + (https://codeberg.org/dnkl/yambar/issues/48). ### Security diff --git a/tag.c b/tag.c index 02e0794..5b00218 100644 --- a/tag.c +++ b/tag.c @@ -446,8 +446,9 @@ tags_expand_template(const char *template, const struct tag_set *tags) } /* Lookup tag */ - const struct tag *tag = tag_for_name(tags, tag_name); - if (tag == NULL) { + const struct tag *tag = NULL; + + if (tag_name == NULL || (tag = tag_for_name(tags, tag_name)) == NULL) { /* No such tag, copy as-is instead */ sbuf_append_at_most(&formatted, template, begin - template + 1); template = begin + 1;