[FFmpeg-devel] [PATCH] avdevice/xcbgrab: check return values of xcb query functions

Moritz Barsnick barsnick at gmx.net
Wed Jun 27 11:21:51 EEST 2018


xcb_query_pointer_reply() and xcb_get_geometry_reply() can return NULL
if e.g. the X server closes or the connection is lost. This needs to
be checked in order to cleanly exit, because the returned pointers are
dereferenced later.

Signed-off-by: Moritz Barsnick <barsnick at gmx.net>
---
 libavdevice/xcbgrab.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index 6d142abd4f..ccab777c6e 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -404,7 +404,16 @@ static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
         pc  = xcb_query_pointer(c->conn, c->screen->root);
         gc  = xcb_get_geometry(c->conn, c->screen->root);
         p   = xcb_query_pointer_reply(c->conn, pc, NULL);
+        if (!p) {
+            av_log(c, AV_LOG_ERROR, "Cannot get xcb pointer\n");
+            return AVERROR(EIO);
+        }
         geo = xcb_get_geometry_reply(c->conn, gc, NULL);
+        if (!geo) {
+            av_log(c, AV_LOG_ERROR, "Cannot get xcb geometry\n");
+            free(p);
+            return AVERROR(EIO);
+        }
     }
 
     if (c->follow_mouse && p->same_screen)
@@ -537,6 +546,10 @@ static int create_stream(AVFormatContext *s)
 
     gc  = xcb_get_geometry(c->conn, c->screen->root);
     geo = xcb_get_geometry_reply(c->conn, gc, NULL);
+    if (!geo) {
+        av_log(c, AV_LOG_ERROR, "Cannot get xcb geometry\n");
+        return AVERROR(EIO);
+    }
 
     if (c->x + c->width > geo->width ||
         c->y + c->height > geo->height) {
-- 
2.14.4



More information about the ffmpeg-devel mailing list