From 06cce36c6d256c45bed01dfd30fda3587c42f6e3 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 18 Jul 2016 23:10:33 +0200 Subject: [PATCH] Properly handle failures of Xv query functions. If one of the query functions fail, xvinfo does not properly handle these cases and will most likely run into a segmentation fault due to accessing uninitialized variables (which includes pointers). Signed-off-by: Tobias Stoeckmann --- xvinfo.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/xvinfo.c b/xvinfo.c index 891c8c2..db1a008 100644 --- a/xvinfo.c +++ b/xvinfo.c @@ -71,7 +71,7 @@ main(int argc, char *argv[]) exit(-1); } - if ((Success != XvQueryExtension(dpy, &ver, &rev, &reqB, &eventB, &errorB))) { + if (Success != XvQueryExtension(dpy, &ver, &rev, &reqB, &eventB, &errorB)) { fprintf(stderr, "%s: No X-Video Extension on %s\n", progname, (disname != NULL) ? disname : XDisplayName(NULL)); exit(0); @@ -84,7 +84,12 @@ main(int argc, char *argv[]) for (i = 0; i < nscreens; i++) { fprintf(stdout, "screen #%i\n", i); - XvQueryAdaptors(dpy, RootWindow(dpy, i), &nadaptors, &ainfo); + if (Success != XvQueryAdaptors(dpy, RootWindow(dpy, i), &nadaptors, + &ainfo)) { + fprintf(stderr, "%s: Failed to query adaptors on display %s\n", + progname, (disname != NULL) ? disname : XDisplayName(NULL)); + exit(-1); + } if (!nadaptors) { fprintf(stdout, " no adaptors present\n"); @@ -178,7 +183,14 @@ main(int argc, char *argv[]) fprintf(stdout, " no port attributes defined\n"); } - XvQueryEncodings(dpy, ainfo[j].base_id, &nencode, &encodings); + if (Success != XvQueryEncodings(dpy, ainfo[j].base_id, &nencode, + &encodings)) { + fprintf(stderr, + "%s: Failed to query encodings on display %s\n", + progname, + (disname != NULL) ? disname : XDisplayName(NULL)); + exit(-1); + } if (encodings && nencode) { unsigned int ImageEncodings = 0; -- 2.9.1