From 24d2c9de3de73f8b52026deb7f177ede250a5043 Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 14 Jul 2016 18:08:39 -0400 Subject: [PATCH] yuvjpeg: fix NULL dereference on invalid format string (cherry picked from daala commit 82e51ebb8545d99316dbeaeeef3d7b5a929702e8) --- yuvjpeg.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/yuvjpeg.c b/yuvjpeg.c index 4914b4c4..92d0d8d8 100644 --- a/yuvjpeg.c +++ b/yuvjpeg.c @@ -91,8 +91,7 @@ void extend_edge(JSAMPLE *image, int width, int height, unsigned char *yuv, int main(int argc, char *argv[]) { long quality; - const char *size; - char *x; + int matches; int luma_width; int luma_height; int chroma_width; @@ -131,19 +130,8 @@ int main(int argc, char *argv[]) { return 1; } - size = argv[2]; - x = strchr(size, 'x'); - if (!x && x != size && x != (x + strlen(x) - 1)) { - fprintf(stderr, "Invalid image size input!\n"); - return 1; - } - luma_width = (int)strtol(size, NULL, 10); - if (errno != 0) { - fprintf(stderr, "Invalid image size input!\n"); - return 1; - } - luma_height = (int)strtol(x + 1, NULL, 10); - if (errno != 0) { + matches = sscanf(argv[2], "%dx%d", &luma_width, &luma_height); + if (matches != 2) { fprintf(stderr, "Invalid image size input!\n"); return 1; }