barbieri pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=ae054e6c0bb5cab6ca126c152057e5243ab31dfa

commit ae054e6c0bb5cab6ca126c152057e5243ab31dfa
Author: Gustavo Sverzut Barbieri <[email protected]>
Date:   Mon Dec 19 11:58:55 2016 -0200

    ecore_con/ecore_ipc legacy: fail early for local sockets.
    
    In the old/legacy API the socket would be opened early in non-blocking
    mode (connect returned errno==EINPROGRESS), with UNIX socket being
    path-validated early and returning NULL as 'server' handle.
    
    Some applications relied on this instead of monitoring the "ERROR"
    events, considering the connection to be successful if there was a
    handle -- this was the case with Terminology after it moved from DBus
    to Ecore_Ipc.
    
    Although this is not correct, we must keep compatibility and thus we
    stat() in compatibility layer, failing early as the old API would do.
---
 src/lib/ecore_con/ecore_con_legacy.c | 12 ++++++++++++
 src/lib/ecore_ipc/ecore_ipc.c        | 13 +++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/lib/ecore_con/ecore_con_legacy.c 
b/src/lib/ecore_con/ecore_con_legacy.c
index 29d829a..e99b4a9 100644
--- a/src/lib/ecore_con/ecore_con_legacy.c
+++ b/src/lib/ecore_con/ecore_con_legacy.c
@@ -1807,6 +1807,8 @@ _ecore_con_server_dialer_set(Ecore_Con_Server *svr, Eo 
*dialer)
             (type == ECORE_CON_LOCAL_SYSTEM))
      {
         char *path = ecore_con_local_path_new(type == ECORE_CON_LOCAL_SYSTEM, 
svr->name, svr->port);
+        struct stat st;
+
         if (!path)
           {
              ERR("could not create local path for name='%s', port=%d", 
svr->name, svr->port);
@@ -1817,6 +1819,16 @@ _ecore_con_server_dialer_set(Ecore_Con_Server *svr, Eo 
*dialer)
              eina_strlcpy(address, path, sizeof(address));
              free(path);
           }
+
+        if ((stat(address, &st) != 0)
+#ifdef S_ISSOCK
+            || (!S_ISSOCK(st.st_mode))
+#endif
+            )
+          {
+             DBG("%s is not a socket", address);
+             return EINA_FALSE;
+          }
      }
 
    if ((svr->type & ECORE_CON_NO_PROXY) == ECORE_CON_NO_PROXY)
diff --git a/src/lib/ecore_ipc/ecore_ipc.c b/src/lib/ecore_ipc/ecore_ipc.c
index dfacf93..40a1e1e 100644
--- a/src/lib/ecore_ipc/ecore_ipc.c
+++ b/src/lib/ecore_ipc/ecore_ipc.c
@@ -4,6 +4,7 @@
 
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #ifdef HAVE_ARPA_INET_H
 # include <arpa/inet.h>
@@ -761,9 +762,21 @@ ecore_ipc_server_connect(Ecore_Ipc_Type type, char *name, 
int port, const void *
 #ifdef EFL_NET_DIALER_UNIX_CLASS
    if ((type & ECORE_IPC_TYPE) == ECORE_IPC_LOCAL_USER)
      {
+        struct stat st;
+
         address = ecore_con_local_path_new(EINA_FALSE, name, port);
         EINA_SAFETY_ON_NULL_GOTO(address, error_dialer);
 
+        if ((stat(address, &st) != 0)
+#ifdef S_ISSOCK
+            || (!S_ISSOCK(st.st_mode))
+#endif
+            )
+          {
+             DBG("%s is not a socket", address);
+             goto error_dialer;
+          }
+
         svr->dialer.dialer = efl_add(EFL_NET_DIALER_UNIX_CLASS, 
ecore_main_loop_get());
         EINA_SAFETY_ON_NULL_GOTO(svr->dialer.dialer, error_dialer);
      }

-- 


Reply via email to