Sophie

Sophie

distrib > Mandriva > 2011.0 > i586 > by-pkgid > 4d0621b8275dee58f941c69b4011ed57 > files > 1

gif2png-2.5.4-2.src.rpm

Fixes cmdline buffer overflow described in

http://lists.grok.org.uk/pipermail/full-disclosure/2009-December/072002.html
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=550978

--- gif2png.c	2010-10-20 16:20:07.000000000 +0200
+++ gif2png.c.oden	2011-01-14 17:45:29.855499816 +0100
@@ -675,7 +675,10 @@ int processfile(char *fname, FILE *fp)
 
     strcpy(outname, fname);
 
-    file_ext = outname+strlen(outname)-4;
+    file_ext = outname+strlen(outname);
+    if (file_ext >= outname + 4)
+	file_ext -= 4;
+
     if (strcmp(file_ext, ".gif") != 0 && strcmp(file_ext, ".GIF") != 0 &&
 	strcmp(file_ext, "_gif") != 0 && strcmp(file_ext, "_GIF") != 0) {
 	/* try to derive basename */
@@ -863,6 +866,14 @@ int main(int argc, char *argv[])
 	}
     } else {
 	for (i = ac;i<argc; i++) {
+	    /* make sure that there is enough space for a '.p<NUM>' suffix;
+	       this check catches also the '.gif' case below. */
+	    if (strlen(argv[i]) >= sizeof name - sizeof ".p" - 3 * sizeof(int)) {
+		fprintf(stderr, "%s: name too long\n", argv[i]);
+		errors = 1;
+		continue;
+	    }
+
 	    strcpy(name, argv[i]);
 	    if ((fp = fopen(name, "rb")) == NULL) {
 		/* retry with .gif appended */