From b086401357cfdf02cbd52d29dcd604f6cabaa1d8 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 18 Jul 2016 23:10:33 +0200 Subject: 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 Signed-off-by: Alan Coopersmith --- 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; -- cgit v1.2.3