[gimp] app: add a check on not-NULL string before g_utf8_validate().



commit 98a575370c4595d44acfc6806ef848f25653d427
Author: Jehan <jehan girinstud io>
Date:   Sat May 5 15:55:30 2018 +0200

    app: add a check on not-NULL string before g_utf8_validate().
    
    Still looking for possible crash case during gimp_font_list_load_names()
    (cf. bug 795650). g_utf8_validate() segfaults if called with NULL.
    Though looking at pango_font_description_to_string() implementation, it
    doesn't look like it would ever return NULL. Yet it is worth
    double-checking. We don't load font every second anyway.

 app/text/gimpfontlist.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/app/text/gimpfontlist.c b/app/text/gimpfontlist.c
index 7491fcd..7832978 100644
--- a/app/text/gimpfontlist.c
+++ b/app/text/gimpfontlist.c
@@ -129,7 +129,12 @@ gimp_font_list_add_font (GimpFontList         *list,
 
   name = pango_font_description_to_string (desc);
 
-  if (g_utf8_validate (name, -1, NULL))
+  /* It doesn't look like pango_font_description_to_string() could ever
+   * return NULL. But just to be double sure and avoid a segfault, I
+   * check before validating the string.
+   */
+  if (name && strlen (name) > 0 &&
+      g_utf8_validate (name, -1, NULL))
     {
       GimpFont *font;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]