]> git.sesse.net Git - ffmpeg/commitdiff
avdevice/xcbgrab: check return values of xcb query functions
authorMoritz Barsnick <barsnick@gmx.net>
Wed, 5 Aug 2020 12:06:53 +0000 (14:06 +0200)
committerAndriy Gelman <andriy.gelman@gmail.com>
Sat, 15 Aug 2020 19:32:52 +0000 (15:32 -0400)
Fixes #7312, segmentation fault on close of X11 server

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@gmx.net>
Reviewed-by: Andriy Gelman <andriy.gelman@gmail.com>
libavdevice/xcbgrab.c

index 6f6b2dbf157ee2b032b0a5800c75fea1de649b25..8ef2a30d02fb7f78431f64bb8bdf62272bd639b2 100644 (file)
@@ -425,7 +425,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(s, AV_LOG_ERROR, "Failed to query xcb pointer\n");
+            return AVERROR_EXTERNAL;
+        }
         geo = xcb_get_geometry_reply(c->conn, gc, NULL);
+        if (!geo) {
+            av_log(s, AV_LOG_ERROR, "Failed to get xcb geometry\n");
+            free(p);
+            return AVERROR_EXTERNAL;
+        }
     }
 
     if (c->follow_mouse && p->same_screen)