talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 0641e8ab944527636061fc4253408ec0de79607e
parent c8813ed987cc450627ab73bd8bf7838dfd710bbc
Author: Ricardo Mones <ricardo@mones.org>
Date:   Thu,  4 Oct 2018 10:30:12 +0200

Fix CID 1439871 and validate Unicode char strictly

Diffstat:
Msrc/entity.c | 16++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/entity.c b/src/entity.c @@ -337,7 +337,7 @@ static gchar *entity_decode_numeric(gchar *str) gchar b[ENTITY_MAX_LEN]; gchar *p = str, *res; gboolean hex = FALSE; - gunichar c = -1; + gunichar c = 0; gint ret; ++p; @@ -357,17 +357,13 @@ static gchar *entity_decode_numeric(gchar *str) if (strlen(b) > 0) c = g_ascii_strtoll (b, NULL, (hex ? 16 : 10)); - if (c < 0) { - /* Obviously invalid */ - debug_print("Numeric reference '&#%s;' is invalid\n", b); - return NULL; - } else if (c >= 0 && c <= 31) { + if (c >= 0 && c <= 31) /* An unprintable character; return the Unicode replacement symbol */ return g_strdup("\xef\xbf\xbd"); - } else if (c > 0x10ffff) { - /* Make sure the character falls within the Unicode codespace - * (0x0 - 0x10ffff) */ - debug_print("Numeric reference '&#%s;' is invalid, outside of Unicode codespace\n", b); + + if (!g_unichar_validate(c)) { + /* Make sure the character is valid Unicode */ + debug_print("Numeric reference '&#%s;' is invalid in Unicode codespace\n", b); return NULL; }