elm: atspi: add null check and fix crash from plug_id
authorJunsuChoi <jsuya.choi@samsung.com>
Thu, 16 Nov 2017 07:46:46 +0000 (16:46 +0900)
committerJiyoun Park <jy0703.park@samsung.com>
Thu, 21 Dec 2017 01:12:27 +0000 (10:12 +0900)
   The format of receiving plug_id may change, causing a crash.
   So add null check and set bus value from 0 to split.

   original patch : cee0b0f4a74629bf5d6f77cc0936dc87aebf44e8

Change-Id: Ic59925c438135c9fedfa9bed4e1c374f27d5a90d

src/lib/elementary/elm_atspi_bridge.c

index dda0916..6110f27 100644 (file)
@@ -2041,17 +2041,27 @@ _elm_atspi_bridge_plug_id_split(const char *plug_id, char **bus, char **path)
    Eina_Bool ret = EINA_FALSE;
    if (tokens == 2)
      {
-        if (bus) *bus = strdup(split[1]);
-        if (path) *path = strdup(split[2]);
-        ret = EINA_TRUE;
+        if (!split[0] || !split[1])
+          ret = EINA_FALSE;
+        else
+          {
+             if (bus) *bus = strdup(split[0]);
+             if (path) *path = strdup(split[1]);
+             ret = EINA_TRUE;
+          }
      }
    else if (tokens == 3)
      {
-        char buf[128];
-        snprintf(buf, sizeof(buf), ":%s", split[1]);
-        if (bus) *bus = strdup(buf);
-        if (path) *path = strdup(split[2]);
-        ret = EINA_TRUE;
+        if (!split[0] || !split[1] || !split[2])
+          ret = EINA_FALSE;
+        else
+          {
+             char buf[128];
+             snprintf(buf, sizeof(buf), "%s:%s",split[0], split[1]);
+             if (bus) *bus = strdup(buf);
+             if (path) *path = strdup(split[2]);
+             ret = EINA_TRUE;
+          }
      }
 
    free(split[0]);