Skip to contentSkip to conversation

v4l-utils: Fix crashes found by Mayhem

PATCH In review Gregor Jasny 2 participants 4 messages Jun 27, 2013 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover v4l-utils: Fix crashes found by Mayhem

The Mayhem Team ran their code checker over the Debian archive and also found two crashes in v4l-utils.

See http://lists.debian.org/debian-devel/2013/06/msg00720.html

Gregor Jasny (2):
libv4lconvert: Prevent integer overflow by checking width and height
keytable: Always check if strtok return value is null

 lib/libv4lconvert/ov511-decomp.c |  7 ++++++-
 lib/libv4lconvert/ov518-decomp.c |  7 ++++++-
 utils/keytable/keytable.c        | 19 ++++++++++++++++---
 3 files changed, 28 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 libv4lconvert: Prevent integer overflow by checking width and height

The Mayhem Team found a crash caused by an integer overflow. Details are here:
http://www.forallsecure.com/bug-reports/8aae67d864bce76993f3f9812b4a2aeea0eb38da/

---
 lib/libv4lconvert/ov511-decomp.c | 7 ++++++-
 lib/libv4lconvert/ov518-decomp.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
lib/libv4lconvert/ov511-decomp.c +6 -1
index 90fc4b1..971d497 100644
@@ -14,6 +14,7 @@
  * Free Software Foundation; version 2 of the License.
  */
 
+#include <limits.h>
 #include <string.h>
 #include <unistd.h>
 #include "helper-funcs.h"
@@ -640,7 +641,11 @@ int main(int argc, char *argv[])
 
 
 		dest_size = width * height * 3 / 2;
-		if (dest_size > sizeof(dest_buf)) {
+		if (width <= 0 || width > SHRT_MAX || height <= 0 || height > SHRT_MAX) {
+			fprintf(stderr, "%s: error: width or height out of bounds\n",
+					argv[0]);
+			dest_size = -1;
+		} else if (dest_size > sizeof(dest_buf)) {
 			fprintf(stderr, "%s: error: dest_buf too small, need: %d\n",
 					argv[0], dest_size);
 			dest_size = -1;
lib/libv4lconvert/ov518-decomp.c +6 -1
index 47b5cbb..91d908c 100644
@@ -15,6 +15,7 @@
  * Free Software Foundation; version 2 of the License.
  */
 
+#include <limits.h>
 #include <string.h>
 #include <unistd.h>
 #include "helper-funcs.h"
@@ -1454,7 +1455,11 @@ int main(int argc, char *argv[])
 
 
 		dest_size = width * height * 3 / 2;
-		if (dest_size > sizeof(dest_buf)) {
+		if (width <= 0 || width > SHRT_MAX || height <= 0 || height > SHRT_MAX) {
+			fprintf(stderr, "%s: error: width or height out of bounds\n",
+					argv[0]);
+			dest_size = -1;
+		} else if (dest_size > sizeof(dest_buf)) {
 			fprintf(stderr, "%s: error: dest_buf too small, need: %d\n",
 					argv[0], dest_size);
 			dest_size = -1;
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 keytable: Always check if strtok return value is null

In reply to Gregor Jasny

The Mayhem Team found a crash caused by a nullptr. Details are here:
http://www.forallsecure.com/bug-reports/567323cd26f180910beb03ae26afb40c432a0c6a/

---
 utils/keytable/keytable.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
utils/keytable/keytable.c +16 -3
index 06b3d95..8bcd5c4 100644
@@ -207,13 +207,19 @@ static error_t parse_keyfile(char *fname, char **table)
 			p++;
 			p = strtok(p, "\n\t =:");
 			do {
+				if (!p)
+					goto err_einval;
 				if (!strcmp(p, "table")) {
 					p = strtok(NULL,"\n, ");
+					if (!p)
+						goto err_einval;
 					*table = malloc(strlen(p) + 1);
 					strcpy(*table, p);
 				} else if (!strcmp(p, "type")) {
 					p = strtok(NULL, " ,\n");
 					do {
+						if (!p)
+							goto err_einval;
 						if (!strcasecmp(p,"rc5") || !strcasecmp(p,"rc-5"))
 							ch_proto |= RC_5;
 						else if (!strcasecmp(p,"rc6") || !strcasecmp(p,"rc-6"))
@@ -447,6 +453,8 @@ static error_t parse_opt(int k, char *arg, struct argp_state *state)
 	case 'p':
 		p = strtok(arg, ",;");
 		do {
+			if (!p)
+				goto err_inval;
 			if (!strcasecmp(p,"rc5") || !strcasecmp(p,"rc-5"))
 				ch_proto |= RC_5;
 			else if (!strcasecmp(p,"rc6") || !strcasecmp(p,"rc-6"))
@@ -813,14 +821,19 @@ static int v1_get_sw_enabled_protocol(char *dirname)
 		return 0;
 	}
 
-	p = strtok(buf, " \n");
-	rc = atoi(p);
-
 	if (fclose(fp)) {
 		perror(name);
 		return errno;
 	}
 
+	p = strtok(buf, " \n");
+	if (!p) {
+		fprintf(stderr, "%s has invalid content: '%s'\n", name, buf);
+		return 0;
+	}
+
+	rc = atoi(p);
+
 	if (debug)
 		fprintf(stderr, "protocol %s is %s\n",
 			name, rc? "enabled" : "disabled");
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Gregor Jasny

Hi,

Thanks for working on this, both patches look good, ack series.

Regards,

Hans

Quoted 14 lines · Gregor Jasny

The Mayhem Team ran their code checker over the Debian archive and also found two crashes in v4l-utils.

See http://lists.debian.org/debian-devel/2013/06/msg00720.html

Gregor Jasny (2):
libv4lconvert: Prevent integer overflow by checking width and height
keytable: Always check if strtok return value is null

  lib/libv4lconvert/ov511-decomp.c |  7 ++++++-
  lib/libv4lconvert/ov518-decomp.c |  7 ++++++-
  utils/keytable/keytable.c        | 19 ++++++++++++++++---
  3 files changed, 28 insertions(+), 5 deletions(-)