Fix issues detected by static analysis tool 07/139507/10
authorInHong Han <inhong1.han@samsung.com>
Wed, 19 Jul 2017 07:27:22 +0000 (16:27 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 19 Jul 2017 11:35:00 +0000 (20:35 +0900)
Change-Id: Id1adbe7e51d5277fbf20c3604f54215a614a2724

ism/extras/efl_panel/remote_input.cpp
ism/modules/frontend/imdkit/i18nIc.c
ism/modules/frontend/imdkit/i18nMethod.c
ism/modules/frontend/imdkit/i18nPtHdr.c
ism/modules/frontend/imdkit/i18nX.c
ism/src/scim_socket.cpp

index e04c1d9..5b95789 100644 (file)
@@ -115,7 +115,7 @@ finish:
 
 static int open_file(const char *file_name) {
     int file_descriptor = -1;
-    char resolved_path[MAXPATHLEN];
+    char resolved_path[PATH_MAX];
 
     if (realpath(file_name, resolved_path) != NULL && !strcmp(file_name, resolved_path))
         file_descriptor = open(file_name, O_WRONLY | O_NONBLOCK);
@@ -228,7 +228,7 @@ _ecore_wl_keymap_update_cb (void *data, int ev_type, void *event)
      }
 
      const char *dev_name = "Remote-Input(Keyboard)";
-     strncpy(device_key.name, dev_name, sizeof(device_key.name));
+     strncpy(device_key.name, dev_name, sizeof(device_key.name) - 1);
      device_key.id.bustype = BUS_USB;
      device_key.id.vendor = 1;
      device_key.id.product = 1;
@@ -299,7 +299,7 @@ bool Remote_Input::init_uinput_mouse_device()
     }
 
     const char *dev_name = "Remote-Input(Mouse)";
-    strncpy(device_mouse.name, dev_name, sizeof(device_mouse.name));
+    strncpy(device_mouse.name, dev_name, sizeof(device_mouse.name) - 1);
     device_mouse.id.bustype = BUS_USB;
     device_mouse.id.vendor = 1;
     device_mouse.id.product = 1;
index 61b576f..885ec08 100644 (file)
@@ -475,8 +475,10 @@ static XICAttribute *CreateNestedList (CARD16 attr_id,
     /*endif*/
     memset (nest_list, 0, sizeof (XICAttribute));
     nest_list->value = (void *) malloc (value_length);
-    if (nest_list->value == NULL)
+    if (nest_list->value == NULL) {
+        XFree (nest_list);
         return NULL;
+    }
     /*endif*/
     memset (nest_list->value, 0, sizeof (value_length));
 
@@ -537,7 +539,7 @@ static int GetICValue (Xi18n i18n_core,
                     attr_ret[n].attribute_id = xic_attr[j].attribute_id;
                     attr_ret[n].name_length = xic_attr[j].length;
                     attr_ret[n].name = malloc (xic_attr[j].length + 1);
-                   strcpy(attr_ret[n].name, xic_attr[j].name);
+                    strncpy(attr_ret[n].name, xic_attr[j].name, sizeof(attr_ret[n].name) - 1);
                     attr_ret[n].type = xic_attr[j].type;
                     n++;
                     i++;
@@ -558,7 +560,7 @@ static int GetICValue (Xi18n i18n_core,
                 attr_ret[n].attribute_id = xic_attr[j].attribute_id;
                 attr_ret[n].name_length = xic_attr[j].length;
                 attr_ret[n].name = malloc (xic_attr[j].length + 1);
-               strcpy(attr_ret[n].name, xic_attr[j].name);
+                strncpy(attr_ret[n].name, xic_attr[j].name, sizeof(attr_ret[n].name) - 1);
                 attr_ret[n].type = xic_attr[j].type;
                 n++;
                 break;
index f2a5082..2aa3811 100644 (file)
@@ -166,8 +166,8 @@ static Bool GetEncodings(Xi18n i18n_core, XIMEncodings **p_encoding)
     {
         (*p_encoding)->supported_encodings[i]
             = (char *) malloc (strlen (p->supported_encodings[i]) + 1);
-        strcpy ((*p_encoding)->supported_encodings[i],
-                p->supported_encodings[i]);
+        strncpy ((*p_encoding)->supported_encodings[i],
+                p->supported_encodings[i], sizeof((*p_encoding)->supported_encodings[i]) - 1);
     }
     /*endif*/
     return True;
@@ -191,7 +191,7 @@ static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
                 if (!address->im_locale)
                     return IMLocale;
                 /*endif*/
-                strcpy (address->im_locale, p->value);
+                strncpy (address->im_locale, p->value, sizeof(address->im_locale) - 1);
                 address->imvalue_mask |= I18N_IM_LOCALE;
             }
             else if (strcmp (p->name, IMServerTransport) == 0)
@@ -203,7 +203,7 @@ static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
                 if (!address->im_addr)
                     return IMServerTransport;
                 /*endif*/
-                strcpy(address->im_addr, p->value);
+                strncpy(address->im_addr, p->value, sizeof(address->im_addr) - 1);
                 address->imvalue_mask |= I18N_IM_ADDRESS;
             }
             else if (strcmp (p->name, IMServerName) == 0)
@@ -215,7 +215,7 @@ static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
                 if (!address->im_name)
                     return IMServerName;
                 /*endif*/
-                strcpy (address->im_name, p->value);
+                strncpy (address->im_name, p->value, sizeof(address->im_name) - 1);
                 address->imvalue_mask |= I18N_IM_NAME;
             }
             else if (strcmp (p->name, IMServerWindow) == 0)
@@ -341,7 +341,7 @@ static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
                 if (!p->value)
                     return IMLocale;
                 /*endif*/
-                strcpy (p->value, address->im_locale);
+                strncpy (p->value, address->im_locale, sizeof(p->value) - 1);
             }
             else if (strcmp (p->name, IMServerTransport) == 0)
             {
@@ -349,7 +349,7 @@ static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
                 if (!p->value)
                     return IMServerTransport;
                 /*endif*/
-                strcpy (p->value, address->im_addr);
+                strncpy (p->value, address->im_addr, sizeof(p->value) - 1);
             }
             else if (strcmp (p->name, IMServerName) == 0)
             {
@@ -359,7 +359,7 @@ static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
                     if (!p->value)
                         return IMServerName;
                     /*endif*/
-                    strcpy (p->value, address->im_name);
+                    strncpy (p->value, address->im_name, sizeof(p->value) - 1);
                 }
                 else
                 {
index 4c43a37..6407bc5 100644 (file)
@@ -386,7 +386,7 @@ static XIMExt *MakeExtensionList (Xi18n i18n_core,
             ext_list[i].minor_opcode = im_ext[i].minor_opcode;
             ext_list[i].length = im_ext[i].length;
             ext_list[i].name = malloc (im_ext[i].length + 1);
-            strcpy (ext_list[i].name, im_ext[i].name);
+            strncpy (ext_list[i].name, im_ext[i].name, sizeof(ext_list[i].name) - 1);
         }
         /*endfor*/
     }
@@ -404,7 +404,7 @@ static XIMExt *MakeExtensionList (Xi18n i18n_core,
                     ext_list[n].minor_opcode = im_ext[i].minor_opcode;
                     ext_list[n].length = im_ext[i].length;
                     ext_list[n].name = malloc (im_ext[i].length + 1);
-                    strcpy (ext_list[n].name, im_ext[i].name);
+                    strncpy (ext_list[n].name, im_ext[i].name, sizeof(ext_list[n].name) - 1);
                     n++;
                     break;
                 }
index a5ba080..8f0dd5a 100644 (file)
@@ -253,7 +253,8 @@ static char *MakeNewAtom (CARD16 connect_id, char *atomName)
 {
     static int sequence = 0;
     
-    sprintf (atomName,
+    snprintf (atomName,
+             sizeof(atomName),
              "_server%d_%d",
              connect_id,
              ((sequence > 20)  ?  (sequence = 0)  :  sequence++));
index 6c36948..15d8e50 100644 (file)
@@ -92,7 +92,9 @@ __gethostname (const char *host)
     while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen, &hp, &herr)) == ERANGE) {
         /* Enlarge the buffer.  */
         hstbuflen *= 2;
-        tmphstbuf = (char*) realloc (tmphstbuf, hstbuflen);
+        char *hstbuf = (char*) realloc (tmphstbuf, hstbuflen);
+        tmphstbuf = hstbuf;
+        hstbuf = NULL;
     }
 
     /* Found the host */