eo_debug: Fix segfault when parsing EO_LIFECYCLE_DEBUG envvar
authorXavi Artigas <xavierartigas@yahoo.es>
Thu, 21 Jun 2018 11:10:56 +0000 (13:10 +0200)
committerJongmin Lee <jm105.lee@samsung.com>
Thu, 21 Jun 2018 21:44:16 +0000 (06:44 +0900)
Summary:
The 'if' block should only be executed when the string contains the colon and
something else behind, but sscanf cannot be used in this case.
If the string contained no colon, the following line with strchr(s, ':')
returns NULL and everything explodes.

Test Plan: eo_debug -l now works for me without segfaulting.

Reviewers: bu5hm4n, zmike, devilhorns, q66

Subscribers: cedric, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D6347

src/lib/eo/eo.c

index 3799378..63cb2a2 100644 (file)
@@ -3135,10 +3135,10 @@ _eo_log_obj_init(void)
    s = getenv("EO_LIFECYCLE_DEBUG");
    if ((s) && (s[0] != '\0'))
      {
-        int lvl = 1;
-
+        char *es;
+        int lvl = (int)strtol(s, &es, 10);
         _eo_log_objs_level = EO_REF_OP_FREE;
-        if (sscanf(s, "%d:%*s", &lvl) == 1)
+        if ((es != s) && (*es == ':'))
           {
              if (lvl >= 3)
                {
@@ -3152,7 +3152,7 @@ _eo_log_obj_init(void)
                   EINA_LOG_DOM_DBG(_eo_log_objs_dom,
                                    "will log new, free, ref and unref");
                }
-             s = strchr(s, ':') + 1;
+             s = es + 1;
           }
 
         if ((strcmp(s, "*") == 0) || (strcmp(s, "1") == 0))