Module Name:    src
Committed By:   christos
Date:           Sat Nov 24 21:40:02 UTC 2012

Modified Files:
        src/usr.bin/mail: mime_codecs.c

Log Message:
PR/47237: Steffen Nurpmeso: Detect more than 2 pad characters and mark as bad.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/mail/mime_codecs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/mail/mime_codecs.c
diff -u src/usr.bin/mail/mime_codecs.c:1.9 src/usr.bin/mail/mime_codecs.c:1.10
--- src/usr.bin/mail/mime_codecs.c:1.9	Fri Apr 10 09:08:25 2009
+++ src/usr.bin/mail/mime_codecs.c	Sat Nov 24 16:40:02 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mime_codecs.c,v 1.9 2009/04/10 13:08:25 christos Exp $	*/
+/*	$NetBSD: mime_codecs.c,v 1.10 2012/11/24 21:40:02 christos Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
 
 #include <sys/cdefs.h>
 #ifndef __lint__
-__RCSID("$NetBSD: mime_codecs.c,v 1.9 2009/04/10 13:08:25 christos Exp $");
+__RCSID("$NetBSD: mime_codecs.c,v 1.10 2012/11/24 21:40:02 christos Exp $");
 #endif /* not __lint__ */
 
 #include <assert.h>
@@ -237,6 +237,10 @@ mime_b64tobin(char *bin, const char *b64
 		unsigned c = uchar64(q[2]);
 		unsigned d = uchar64(q[3]);
 
+		if (a == BAD || a == EQU || b == BAD || b == EQU ||
+		    c == BAD || d == BAD)
+			return -1;
+
 		*p++ = ((a << 2) | ((b & 0x30) >> 4));
 		if (c == EQU)	{ /* got '=' */
 			if (d != EQU)
@@ -248,9 +252,6 @@ mime_b64tobin(char *bin, const char *b64
 			break;
 		}
 		*p++ = (((c & 0x03) << 6) | d);
-
-		if (a == BAD || b == BAD || c == BAD || d == BAD)
-			return -1;
 	}
 
 #undef uchar64

Reply via email to