From 24c31a1fb8155d3ecba7c9e39ae52d1457118036 Mon Sep 17 00:00:00 2001 From: Wonki Kim Date: Wed, 13 Feb 2019 04:06:36 +0000 Subject: [PATCH] ecore_con: Fix potentional problems around ecore_con non-thread safe functions are used like rand(), strerror(). this patch replace them with thread safe one. and also this patch contains a change to fix a memory leak problem. Reviewed-by: Cedric BAIL Differential Revision: https://phab.enlightenment.org/D7917 Change-Id: Ibfa8cbdef468666c738ebd4d7ca725c2bd06dd05 --- src/lib/ecore_con/ecore_con.c | 6 +++--- src/lib/ecore_con/ecore_con_legacy.c | 2 +- src/lib/ecore_con/ecore_con_local.c | 4 ++-- src/lib/ecore_con/ecore_con_url.c | 2 +- src/lib/ecore_con/efl_net_dialer_http.c | 2 +- src/lib/ecore_con/efl_net_server_fd.c | 6 +++--- src/lib/ecore_con/efl_net_server_udp.c | 9 +++++++-- src/lib/ecore_con/efl_net_socket_udp.c | 2 +- src/lib/ecore_con/efl_net_ssl_ctx-gnutls.c | 2 +- src/lib/ecore_con/efl_net_ssl_ctx-openssl.c | 2 +- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c index 84db86a..d195798 100644 --- a/src/lib/ecore_con/ecore_con.c +++ b/src/lib/ecore_con/ecore_con.c @@ -201,7 +201,7 @@ efl_net_unix_fmt(char *buf, size_t buflen, SOCKET fd, const struct sockaddr_un * int r = snprintf(buf, buflen, "unnamed:" SOCKET_FMT, fd); if (r < 0) { - ERR("snprintf(): %s", strerror(errno)); + ERR("snprintf(): %s", eina_error_msg_get(errno)); return EINA_FALSE; } else if ((size_t)r > buflen) @@ -330,7 +330,7 @@ efl_net_ip_port_fmt(char *buf, size_t buflen, const struct sockaddr *addr) if (!inet_ntop(addr->sa_family, mem, p, sizeof(p))) { ERR("inet_ntop(%d, %p, %p, %zd): %s", - addr->sa_family, mem, p, sizeof(p), strerror(errno)); + addr->sa_family, mem, p, sizeof(p), eina_error_msg_get(errno)); return EINA_FALSE; } @@ -341,7 +341,7 @@ efl_net_ip_port_fmt(char *buf, size_t buflen, const struct sockaddr *addr) if (r < 0) { - ERR("could not snprintf(): %s", strerror(errno)); + ERR("could not snprintf(): %s", eina_error_msg_get(errno)); return EINA_FALSE; } else if ((size_t)r > buflen) diff --git a/src/lib/ecore_con/ecore_con_legacy.c b/src/lib/ecore_con/ecore_con_legacy.c index dcb2260..4a5f97b 100644 --- a/src/lib/ecore_con/ecore_con_legacy.c +++ b/src/lib/ecore_con/ecore_con_legacy.c @@ -2661,7 +2661,7 @@ _ecore_con_lookup_done_cb(void *data, const char *host, const char *port EINA_UN if (!inet_ntop(result->ai_family, mem, ip, sizeof(ip))) { - ERR("could not convert IP to string: %s", strerror(errno)); + ERR("could not convert IP to string: %s", eina_error_msg_get(errno)); goto end; } ctx->cb(result->ai_canonname, ip, result->ai_addr, result->ai_addrlen, (void *)ctx->data); diff --git a/src/lib/ecore_con/ecore_con_local.c b/src/lib/ecore_con/ecore_con_local.c index 4b515e1..4144aa7 100644 --- a/src/lib/ecore_con/ecore_con_local.c +++ b/src/lib/ecore_con/ecore_con_local.c @@ -129,7 +129,7 @@ _ecore_con_local_mkpath(const char *path, mode_t mode) { if (errno != EEXIST) { - ERR("could not create parent directory '%s' of path '%s': %s", d, path, strerror(errno)); + ERR("could not create parent directory '%s' of path '%s': %s", d, path, eina_error_msg_get(errno)); goto end; } } @@ -140,7 +140,7 @@ _ecore_con_local_mkpath(const char *path, mode_t mode) if (mkdir(d, mode) != 0) { if (errno != EEXIST) - ERR("could not create parent directory '%s' of path '%s': %s", d, path, strerror(errno)); + ERR("could not create parent directory '%s' of path '%s': %s", d, path, eina_error_msg_get(errno)); else { struct stat st; diff --git a/src/lib/ecore_con/ecore_con_url.c b/src/lib/ecore_con/ecore_con_url.c index ae4cf33..4582f4a 100644 --- a/src/lib/ecore_con/ecore_con_url.c +++ b/src/lib/ecore_con/ecore_con_url.c @@ -429,7 +429,7 @@ _ecore_con_url_dialer_can_read_changed(void *data, const Efl_Event *event EINA_U ssize_t r = write(url_con->write_fd, slice.bytes, slice.len); if (r == -1) { - ERR("Could not write to fd=%d: %s", url_con->write_fd, strerror(errno)); + ERR("Could not write to fd=%d: %s", url_con->write_fd, eina_error_msg_get(errno)); break; } slice.bytes += r; diff --git a/src/lib/ecore_con/efl_net_dialer_http.c b/src/lib/ecore_con/efl_net_dialer_http.c index 8bfe967..9246768 100644 --- a/src/lib/ecore_con/efl_net_dialer_http.c +++ b/src/lib/ecore_con/efl_net_dialer_http.c @@ -1796,7 +1796,7 @@ _efl_net_dialer_http_efl_io_closer_close_on_exec_set(Eo *o EINA_UNUSED, Efl_Net_ if (!eina_file_close_on_exec(pd->fd, close_on_exec)) { - ERR("fcntl(" SOCKET_FMT ", F_SETFD): %s", pd->fd, strerror(errno)); + ERR("fcntl(" SOCKET_FMT ", F_SETFD): %s", pd->fd, eina_error_msg_get(errno)); pd->close_on_exec = old; return EINA_FALSE; } diff --git a/src/lib/ecore_con/efl_net_server_fd.c b/src/lib/ecore_con/efl_net_server_fd.c index 8a49340..28626b0 100644 --- a/src/lib/ecore_con/efl_net_server_fd.c +++ b/src/lib/ecore_con/efl_net_server_fd.c @@ -54,7 +54,7 @@ efl_net_accept4(SOCKET fd, struct sockaddr *addr, socklen_t *addrlen, Eina_Bool if (!eina_file_close_on_exec(client, EINA_TRUE)) { int errno_bkp = errno; - ERR("fcntl(" SOCKET_FMT ", F_SETFD, FD_CLOEXEC): %s", client, strerror(errno)); + ERR("fcntl(" SOCKET_FMT ", F_SETFD, FD_CLOEXEC): %s", client, eina_error_msg_get(errno)); closesocket(client); errno = errno_bkp; return INVALID_SOCKET; @@ -282,7 +282,7 @@ _efl_net_server_fd_close_on_exec_set(Eo *o, Efl_Net_Server_Fd_Data *pd, Eina_Boo if (!eina_file_close_on_exec(fd, close_on_exec)) { - ERR("fcntl(" SOCKET_FMT ", F_SETFD,): %s", fd, strerror(errno)); + ERR("fcntl(" SOCKET_FMT ", F_SETFD,): %s", fd, eina_error_msg_get(errno)); pd->close_on_exec = old; return EINA_FALSE; } @@ -311,7 +311,7 @@ _efl_net_server_fd_close_on_exec_get(const Eo *o, Efl_Net_Server_Fd_Data *pd) flags = fcntl(fd, F_GETFD); if (flags < 0) { - ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", fd, strerror(errno)); + ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", fd, eina_error_msg_get(errno)); return EINA_FALSE; } diff --git a/src/lib/ecore_con/efl_net_server_udp.c b/src/lib/ecore_con/efl_net_server_udp.c index ced3e04..50a0c97 100644 --- a/src/lib/ecore_con/efl_net_server_udp.c +++ b/src/lib/ecore_con/efl_net_server_udp.c @@ -171,7 +171,7 @@ _efl_net_server_udp_resolved(void *data, const char *host EINA_UNUSED, const cha Eo *o = data; Efl_Net_Server_Udp_Data *pd = efl_data_scope_get(o, MY_CLASS); const struct addrinfo *addr; - Eina_Error err; + Eina_Error err = EINA_ERROR_NO_ERROR; pd->resolver = NULL; @@ -351,6 +351,7 @@ _efl_net_server_udp_efl_net_server_fd_process_incoming_data(Eo *o, Efl_Net_Serve client = eina_hash_find(pd->clients, str); if (client) { + free(buf); _efl_net_server_udp_client_feed(client, slice); return; } @@ -393,8 +394,12 @@ _efl_net_server_udp_efl_net_server_fd_process_incoming_data(Eo *o, Efl_Net_Serve efl_event_callback_add(client, EFL_IO_CLOSER_EVENT_CLOSED, _efl_net_server_udp_client_event_closed, o); if (!efl_net_server_client_announce(o, client)) - return; + { + free(buf); + return; + } + free(buf); _efl_net_server_udp_client_feed(client, slice); } diff --git a/src/lib/ecore_con/efl_net_socket_udp.c b/src/lib/ecore_con/efl_net_socket_udp.c index 29b66f3..67e3f6a 100644 --- a/src/lib/ecore_con/efl_net_socket_udp.c +++ b/src/lib/ecore_con/efl_net_socket_udp.c @@ -119,7 +119,7 @@ _efl_net_socket_udp_bind(Eo *o, Efl_Net_Socket_Udp_Data *pd) if (errno) { err = errno; - ERR("invalid port numer '%s': %s", bport, strerror(errno)); + ERR("invalid port numer '%s': %s", bport, eina_error_msg_get(errno)); goto error_bind; } diff --git a/src/lib/ecore_con/efl_net_ssl_ctx-gnutls.c b/src/lib/ecore_con/efl_net_ssl_ctx-gnutls.c index 7a92a82..cb19808 100644 --- a/src/lib/ecore_con/efl_net_ssl_ctx-gnutls.c +++ b/src/lib/ecore_con/efl_net_ssl_ctx-gnutls.c @@ -125,7 +125,7 @@ _efl_net_ssl_ctx_load_lists(Efl_Net_Ssl_Ctx *ctx, Efl_Net_Ssl_Ctx_Config cfg) r = 0; if (stat(path, &st) != 0) { - ERR("ssl_ctx=%p could not load certificate authorities from '%s': %s", ctx, path, strerror(errno)); + ERR("ssl_ctx=%p could not load certificate authorities from '%s': %s", ctx, path, eina_error_msg_get(errno)); eina_stringshare_del(path); *cfg.certificate_authorities = eina_list_remove_list(*cfg.certificate_authorities, n); continue; diff --git a/src/lib/ecore_con/efl_net_ssl_ctx-openssl.c b/src/lib/ecore_con/efl_net_ssl_ctx-openssl.c index 6efba84..d8e4b6e 100644 --- a/src/lib/ecore_con/efl_net_ssl_ctx-openssl.c +++ b/src/lib/ecore_con/efl_net_ssl_ctx-openssl.c @@ -196,7 +196,7 @@ _efl_net_ssl_ctx_check_errors(); if (stat(path, &st) != 0) { - ERR("ssl_ctx=%p could not load certificate authorities from '%s': %s", ctx, path, strerror(errno)); + ERR("ssl_ctx=%p could not load certificate authorities from '%s': %s", ctx, path, eina_error_msg_get(errno)); eina_stringshare_del(path); *cfg.certificate_authorities = eina_list_remove_list(*cfg.certificate_authorities, n); continue; -- 2.7.4