summaryrefslogtreecommitdiff
path: root/chat/libotr/patches/patch-CVE-2012-3461-ad
blob: 478448a2d33d9b91bd220409382b03a660ef32a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$NetBSD: patch-CVE-2012-3461-ad,v 1.1 2012/08/09 10:06:47 drochner Exp $

--- toolkit/parse.c.orig	2008-05-27 12:35:28.000000000 +0000
+++ toolkit/parse.c
@@ -64,7 +64,8 @@ static unsigned char *decode(const char 
 {
     const char *header, *footer;
     unsigned char *raw;
-	
+    size_t rawlen;
+
     /* Find the header */
     header = strstr(msg, "?OTR:");
     if (!header) return NULL;
@@ -75,8 +76,10 @@ static unsigned char *decode(const char 
     footer = strchr(header, '.');
     if (!footer) footer = header + strlen(header);
 
-    raw = malloc((footer-header) / 4 * 3);
-    if (raw == NULL && (footer-header >= 4)) return NULL;
+    rawlen = OTRL_B64_MAX_DECODED_SIZE(footer-header);
+
+    raw = malloc(rawlen);
+    if (raw == NULL && rawlen > 0) return NULL;
     *lenp = otrl_base64_decode(raw, header, footer-header);
 
     return raw;