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

Submitted by Moritz Barsnick on June 27, 2018, 8:21 a.m.

Details

Message ID 20180627082151.9794-1-barsnick@gmx.net
State New
Headers show

Commit Message

Moritz Barsnick June 27, 2018, 8:21 a.m.
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>
---
 libavdevice/xcbgrab.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Moritz Barsnick June 27, 2018, 8:26 a.m.
On Wed, Jun 27, 2018 at 10:21:51 +0200, Moritz Barsnick wrote:
> Subject: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: check return values of xcb query functions

Sorry, I had told git send-email to use [PATCH v2]. *shrug*

> +        if (!p) {
> +            av_log(c, AV_LOG_ERROR, "Cannot get xcb pointer\n");

The value of the messages is debatable. Feel free to discuss.

This gives such an error using ffmpeg command line with this patch:
> [xcbgrab indev @ 0xa156740] Cannot get xcb pointer
> :1: Input/output error

The last line may suffice.

Thanks,
Moritz

Patch hide | download patch | download mbox

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