From: U. Artie Eoff Date: Tue, 14 Nov 2017 17:24:44 +0000 (-0800) Subject: va_fool: check fstat result X-Git-Tag: android-x86-8.1-r1~111 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4794b9989b91a3326d1819b972ec9d48e4b78139;p=android-x86%2Fhardware-intel-common-libva.git va_fool: check fstat result Check fstat return value for errors before attempting to use the result. Signed-off-by: U. Artie Eoff --- diff --git a/va/va_fool.c b/va/va_fool.c index 4dd809d..9281129 100644 --- a/va/va_fool.c +++ b/va/va_fool.c @@ -277,11 +277,17 @@ static int va_FoolFillCodedBufEnc(VADisplay dpy, struct fool_context *fool_ctx) fool_ctx->file_count); if ((fd = open(file_name, O_RDONLY)) != -1) { - fstat(fd, &file_stat); - fool_ctx->file_count++; /* open next file */ - break; - } else /* fall back to the first file file */ - fool_ctx->file_count = 0; + if (fstat(fd, &file_stat) != -1) { + fool_ctx->file_count++; /* open next file */ + break; + } + va_errorMessage(dpy, "Identify file %s failed:%s\n", + file_name, strerror(errno)); + close(fd); + fd = -1; + } + /* fall back to the first file file */ + fool_ctx->file_count = 0; } if (fd != -1) { fool_ctx->segbuf_enc = realloc(fool_ctx->segbuf_enc, file_stat.st_size); @@ -311,11 +317,15 @@ static int va_FoolFillCodedBufJPG(VADisplay dpy, struct fool_context *fool_ctx) ssize_t ret; if ((fd = open(fool_ctx->fn_jpg, O_RDONLY)) != -1) { - fstat(fd, &file_stat); - fool_ctx->segbuf_jpg = realloc(fool_ctx->segbuf_jpg, file_stat.st_size); - ret = read(fd, fool_ctx->segbuf_jpg, file_stat.st_size); - if (ret < file_stat.st_size) - va_errorMessage(dpy, "Reading file %s failed.\n", fool_ctx->fn_jpg); + if (fstat(fd, &file_stat) != -1) { + fool_ctx->segbuf_jpg = realloc(fool_ctx->segbuf_jpg, file_stat.st_size); + ret = read(fd, fool_ctx->segbuf_jpg, file_stat.st_size); + if (ret < file_stat.st_size) + va_errorMessage(dpy, "Reading file %s failed.\n", fool_ctx->fn_jpg); + } else { + va_errorMessage(dpy, "Identify file %s failed:%s\n", + fool_ctx->fn_jpg, strerror(errno)); + } close(fd); } else va_errorMessage(dpy, "Open file %s failed:%s\n", fool_ctx->fn_jpg, strerror(errno));