summary refs log tree commit diff
path: root/rfc2045.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-16 22:27:13 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-16 22:27:13 +0200
commit61f3ae7d3c239abdfc145bf089598737af7ec678 (patch)
treea23afbffe5ba450359992de48957e87130b9a988 /rfc2045.c
parentcf3b70ed9814483a84979e8f88272f56986e5fb9 (diff)
downloadmblaze-61f3ae7d3c239abdfc145bf089598737af7ec678.tar.gz
mblaze-61f3ae7d3c239abdfc145bf089598737af7ec678.tar.xz
mblaze-61f3ae7d3c239abdfc145bf089598737af7ec678.zip
rfc2045: blaze822_multipart: use blaze822_mime_parameter
Diffstat (limited to 'rfc2045.c')
-rw-r--r--rfc2045.c45
1 files changed, 8 insertions, 37 deletions
diff --git a/rfc2045.c b/rfc2045.c
index 881bd5f..5b6ab4f 100644
--- a/rfc2045.c
+++ b/rfc2045.c
@@ -110,47 +110,18 @@ blaze822_multipart(struct message *msg, struct message **imsg)
 	if (!*s)
 		return 0;
 
-	// XXX scan boundary only once
-	char *boundary = s+1;
-	while (*boundary) {
-		while (iswsp(*boundary))
-			boundary++;
-		if (strncasecmp(boundary, "boundary=", 9) == 0) {
-			boundary += 9;
-			break;
-		}
-		boundary = strchr(boundary+1, ';');
-		if (!boundary)
-			break;
-		boundary++;
-	}
-	if (!boundary || !*boundary)
+	char *boundary, *boundaryend;
+	if (!blaze822_mime_parameter(s, "boundary", &boundary, &boundaryend))
 		return 0;
-	char *e;
-	if (*boundary == '"') {
-		boundary++;
-		e = strchr(boundary, '"');
-		if (!e)
-			return 0;
-	} else {
-		e = boundary;
-		// XXX    bchars := bcharsnospace / " "
-		// bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
-		//              "+" / "_" / "," / "-" / "." /
-		//              "/" / ":" / "=" / "?"
-		while (*e && !iswsp(*e) && *e != ';')
-			e++;
-	}
-
 	char mboundary[256];
+	int boundarylen = boundaryend-boundary+2;
+
+	if (boundarylen >= 256)
+		return 0;
 	mboundary[0] = '-';
 	mboundary[1] = '-';
-	memcpy(mboundary+2, boundary, e-boundary);  // XXX overflow
-	mboundary[e-boundary+2] = 0;
-
-	int boundarylen = e-boundary+2;
-
-//	printf("boundary: %s %s %s\n", ct, cte, boundary);
+	memcpy(mboundary+2, boundary, boundarylen-2);
+	mboundary[boundarylen] = 0;
 
 	char *prevpart;
 	if (*imsg)