From 2d2882b765649b596f0854874f3aaa2319c41d10 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 19 Jul 2017 16:27:22 +0900 Subject: [PATCH] Fix issues detected by static analysis tool Change-Id: Id1adbe7e51d5277fbf20c3604f54215a614a2724 --- ism/extras/efl_panel/remote_input.cpp | 6 +++--- ism/modules/frontend/imdkit/i18nIc.c | 8 +++++--- ism/modules/frontend/imdkit/i18nMethod.c | 16 ++++++++-------- ism/modules/frontend/imdkit/i18nPtHdr.c | 4 ++-- ism/modules/frontend/imdkit/i18nX.c | 3 ++- ism/src/scim_socket.cpp | 4 +++- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/ism/extras/efl_panel/remote_input.cpp b/ism/extras/efl_panel/remote_input.cpp index e04c1d9..5b95789 100644 --- a/ism/extras/efl_panel/remote_input.cpp +++ b/ism/extras/efl_panel/remote_input.cpp @@ -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; diff --git a/ism/modules/frontend/imdkit/i18nIc.c b/ism/modules/frontend/imdkit/i18nIc.c index 61b576f..885ec08 100644 --- a/ism/modules/frontend/imdkit/i18nIc.c +++ b/ism/modules/frontend/imdkit/i18nIc.c @@ -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; diff --git a/ism/modules/frontend/imdkit/i18nMethod.c b/ism/modules/frontend/imdkit/i18nMethod.c index f2a5082..2aa3811 100644 --- a/ism/modules/frontend/imdkit/i18nMethod.c +++ b/ism/modules/frontend/imdkit/i18nMethod.c @@ -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 { diff --git a/ism/modules/frontend/imdkit/i18nPtHdr.c b/ism/modules/frontend/imdkit/i18nPtHdr.c index 4c43a37..6407bc5 100644 --- a/ism/modules/frontend/imdkit/i18nPtHdr.c +++ b/ism/modules/frontend/imdkit/i18nPtHdr.c @@ -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; } diff --git a/ism/modules/frontend/imdkit/i18nX.c b/ism/modules/frontend/imdkit/i18nX.c index a5ba080..8f0dd5a 100644 --- a/ism/modules/frontend/imdkit/i18nX.c +++ b/ism/modules/frontend/imdkit/i18nX.c @@ -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++)); diff --git a/ism/src/scim_socket.cpp b/ism/src/scim_socket.cpp index 6c36948..15d8e50 100644 --- a/ism/src/scim_socket.cpp +++ b/ism/src/scim_socket.cpp @@ -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 */ -- 2.7.4