From 5c5cdbbdf8be231c433e21b050a6c6991d327b61 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 25 Jul 2014 12:21:49 -0400 Subject: [PATCH] Make sure broken feature strings are not partially parsed If user doesn't check hb_feature_from_string() return value, we don't want them to end up see the partially-parsed feature. --- src/hb-shape.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hb-shape.cc b/src/hb-shape.cc index f5a4ef28..efe3bffc 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -37,8 +37,7 @@ static bool parse_space (const char **pp, const char *end) { - char c; - while (*pp < end && (c = **pp, ISSPACE (c))) + while (*pp < end && ISSPACE (**pp)) (*pp)++; return true; } @@ -201,7 +200,7 @@ parse_one_feature (const char **pp, const char *end, hb_feature_t *feature) * hb_feature_from_string: * @str: (array length=len): * @len: - * @feature: (out): + * @feature: (out) (allow-none): * * * @@ -213,10 +212,21 @@ hb_bool_t hb_feature_from_string (const char *str, int len, hb_feature_t *feature) { + hb_feature_t feat; + if (len < 0) len = strlen (str); - return parse_one_feature (&str, str + len, feature); + if (likely (parse_one_feature (&str, str + len, &feat))) + { + if (feature) + *feature = feat; + return true; + } + + if (feature) + memset (feature, 0, sizeof (*feature)); + return false; } /** -- GitLab