devilhorns pushed a commit to branch master.

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

commit adeb28a1c0faf5918bd1676cb3c7e6a7b874b7c6
Author: Chris Michael <cpmich...@osg.samsung.com>
Date:   Thu Feb 11 10:09:51 2016 -0500

    ecore-x: Add EINA_SAFETY checks for missing display
    
    xlib immediately crashes upon being passed a null DISPLAY object,
    so every function in ecore-x should likely have safety checks such
    as these.
    
    @ref 210b3e6c622341d4366c27c4d9bc1086012efd28
    
    @fix
    
    Signed-off-by: Chris Michael <cpmich...@osg.samsung.com>
---
 src/lib/ecore_x/xlib/ecore_x.c        | 24 ++++++++++++++++++++++--
 src/lib/ecore_x/xlib/ecore_x_atoms.c  | 10 ++++------
 src/lib/ecore_x/xlib/ecore_x_cursor.c |  4 ++++
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/lib/ecore_x/xlib/ecore_x.c b/src/lib/ecore_x/xlib/ecore_x.c
index 01b626d..7e9d217 100644
--- a/src/lib/ecore_x/xlib/ecore_x.c
+++ b/src/lib/ecore_x/xlib/ecore_x.c
@@ -879,6 +879,7 @@ EAPI int
 ecore_x_fd_get(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
    return ConnectionNumber(_ecore_x_disp);
 }
 
@@ -891,6 +892,7 @@ EAPI Ecore_X_Screen *
 ecore_x_default_screen_get(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, NULL);
    return (Ecore_X_Screen *)DefaultScreenOfDisplay(_ecore_x_disp);
 }
 
@@ -930,7 +932,7 @@ EAPI int
 ecore_x_screen_count_get(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
-
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
    return ScreenCount(_ecore_x_disp);
 }
 
@@ -961,6 +963,7 @@ ecore_x_screen_index_get(const Ecore_X_Screen *screen)
 EAPI Ecore_X_Screen *
 ecore_x_screen_get(int idx)
 {
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, NULL);
    return XScreenOfDisplay(_ecore_x_disp, idx);
 }
 
@@ -1012,6 +1015,7 @@ EAPI void
 ecore_x_flush(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XFlush(_ecore_x_disp);
 }
 
@@ -1024,6 +1028,7 @@ EAPI void
 ecore_x_sync(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XSync(_ecore_x_disp, False);
 }
 
@@ -1046,6 +1051,7 @@ ecore_x_killall(Ecore_X_Window root)
    unsigned int num_children = 0;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XGrabServer(_ecore_x_disp);
    /* Tranverse window tree starting from root, and drag each
     * before the firing squad */
@@ -1074,6 +1080,7 @@ EAPI void
 ecore_x_kill(Ecore_X_Window win)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XKillClient(_ecore_x_disp, win);
    if (_ecore_xlib_sync) ecore_x_sync();
 }
@@ -1102,6 +1109,7 @@ ecore_x_dpi_get(void)
    Screen *s;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    s = DefaultScreenOfDisplay(_ecore_x_disp);
    if (s->mwidth <= 0)
      return 75;
@@ -1126,6 +1134,7 @@ ecore_x_bell(int percent)
 {
    int ret;
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    ret = XBell(_ecore_x_disp, percent);
    if (ret == BadValue)
      return EINA_FALSE;
@@ -2069,6 +2078,7 @@ ecore_x_client_message32_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    xev.xclient.window = win;
    xev.xclient.type = ClientMessage;
    xev.xclient.message_type = type;
@@ -2104,6 +2114,7 @@ ecore_x_client_message8_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    xev.xclient.window = win;
    xev.xclient.type = ClientMessage;
    xev.xclient.message_type = type;
@@ -2132,6 +2143,7 @@ ecore_x_mouse_move_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    XGetWindowAttributes(_ecore_x_disp, win, &att);
    XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
    xev.xmotion.type = MotionNotify;
@@ -2164,6 +2176,7 @@ ecore_x_mouse_down_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    XGetWindowAttributes(_ecore_x_disp, win, &att);
    XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
    xev.xbutton.type = ButtonPress;
@@ -2196,6 +2209,7 @@ ecore_x_mouse_up_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    XGetWindowAttributes(_ecore_x_disp, win, &att);
    XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
    xev.xbutton.type = ButtonRelease;
@@ -2227,6 +2241,7 @@ ecore_x_mouse_in_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    XGetWindowAttributes(_ecore_x_disp, win, &att);
    XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
    xev.xcrossing.type = EnterNotify;
@@ -2260,6 +2275,7 @@ ecore_x_mouse_out_send(Ecore_X_Window win,
    Eina_Bool ret;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
    XGetWindowAttributes(_ecore_x_disp, win, &att);
    XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
    xev.xcrossing.type = LeaveNotify;
@@ -2285,6 +2301,7 @@ EAPI void
 ecore_x_focus_reset(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XSetInputFocus(_ecore_x_disp, PointerRoot, RevertToPointerRoot, 
CurrentTime);
    if (_ecore_xlib_sync) ecore_x_sync();
 }
@@ -2293,6 +2310,7 @@ EAPI void
 ecore_x_events_allow_all(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XAllowEvents(_ecore_x_disp, AsyncBoth, CurrentTime);
    if (_ecore_xlib_sync) ecore_x_sync();
 }
@@ -2318,6 +2336,7 @@ ecore_x_pointer_xy_get(Ecore_X_Window win,
    unsigned int mask;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    ret = XQueryPointer(_ecore_x_disp, win, &rwin, &cwin,
                        &rx, &ry, &wx, &wy, &mask);
    if (!ret)
@@ -2338,6 +2357,7 @@ ecore_x_pointer_root_xy_get(int *x, int *y)
    unsigned int mask;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    root = ecore_x_window_root_list(&num);
    for (i = 0; i < num; i++) 
      {
@@ -2430,6 +2450,7 @@ EAPI void
 ecore_x_xkb_select_group(int group)
 {
 #ifdef ECORE_XKB
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XkbLockGroup(_ecore_x_disp, XkbUseCoreKbd, group);
    if (_ecore_xlib_sync) ecore_x_sync();
 #endif
@@ -2473,4 +2494,3 @@ _ecore_x_event_modifier(unsigned int state)
 
    return xmodifiers;
 }
-
diff --git a/src/lib/ecore_x/xlib/ecore_x_atoms.c 
b/src/lib/ecore_x/xlib/ecore_x_atoms.c
index 6533f15..b4bb518 100644
--- a/src/lib/ecore_x/xlib/ecore_x_atoms.c
+++ b/src/lib/ecore_x/xlib/ecore_x_atoms.c
@@ -49,6 +49,7 @@ ecore_x_atom_get(const char *name)
      return 0;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    atom = XInternAtom(_ecore_x_disp, name, False);
    if (_ecore_xlib_sync) ecore_x_sync();
    return atom;
@@ -62,10 +63,8 @@ ecore_x_atoms_get(const char **names,
    Atom *atoms_int;
    int i;
 
-   if (!_ecore_x_disp)
-     return;
-
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    atoms_int = alloca(num * sizeof(Atom));
    XInternAtoms(_ecore_x_disp, (char **)names, num, False, atoms_int);
    for (i = 0; i < num; i++)
@@ -79,11 +78,10 @@ ecore_x_atom_name_get(Ecore_X_Atom atom)
    char *name;
    char *xname;
 
-   if (!_ecore_x_disp)
-     return NULL;
-
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, NULL);
+
    xname = XGetAtomName(_ecore_x_disp, atom);
    if (_ecore_xlib_sync) ecore_x_sync();
    if (!xname)
diff --git a/src/lib/ecore_x/xlib/ecore_x_cursor.c 
b/src/lib/ecore_x/xlib/ecore_x_cursor.c
index 19cc233..aacc831 100644
--- a/src/lib/ecore_x/xlib/ecore_x_cursor.c
+++ b/src/lib/ecore_x/xlib/ecore_x_cursor.c
@@ -22,6 +22,7 @@ ecore_x_cursor_new(Ecore_X_Window win,
 {
 #ifdef ECORE_XCURSOR
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
    if (_ecore_x_xcursor)
      {
         Cursor c;
@@ -217,6 +218,7 @@ EAPI void
 ecore_x_cursor_free(Ecore_X_Cursor c)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XFreeCursor(_ecore_x_disp, c);
    if (_ecore_xlib_sync) ecore_x_sync();
 }
@@ -242,6 +244,7 @@ ecore_x_cursor_size_set(int size)
 {
 #ifdef ECORE_XCURSOR
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
    XcursorSetDefaultSize(_ecore_x_disp, size);
    if (_ecore_xlib_sync) ecore_x_sync();
 #else /* ifdef ECORE_XCURSOR */
@@ -254,6 +257,7 @@ ecore_x_cursor_size_get(void)
 {
 #ifdef ECORE_XCURSOR
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
    return XcursorGetDefaultSize(_ecore_x_disp);
 #else /* ifdef ECORE_XCURSOR */
    return 0;

-- 


Reply via email to