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 <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D7917
This commit is contained in:
Wonki Kim 2019-02-13 04:06:36 +00:00 committed by Cedric BAIL
parent 19fcd6e60f
commit 1cdedaa33b
10 changed files with 21 additions and 16 deletions

View File

@ -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)

View File

@ -2659,7 +2659,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);

View File

@ -127,7 +127,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;
}
}
@ -138,7 +138,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;

View File

@ -425,7 +425,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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;