Fix a segfault in base64_encode_data_blob
authorVolker Lendecke <vl@samba.org>
Thu, 10 Jul 2008 16:12:24 +0000 (18:12 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 10 Jul 2008 17:06:26 +0000 (10:06 -0700)
We did not allocate enough memory for the \0 and a = at the end

source/lib/util_str.c

index 6310e2464d06e2209b4a6b9338b7351d5669e61b..6678c0c24de71e08079c7efd9f9e06dbfb5864bf 100644 (file)
@@ -2345,7 +2345,9 @@ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
 
        out_cnt = 0;
        len = data.length;
-       output_len = data.length * 2;
+       output_len = data.length * 2 + 4; /* Account for closing bytes. 4 is
+                                          * random but should be enough for
+                                          * the = and \0 */
        result = TALLOC_ARRAY(mem_ctx, char, output_len); /* get us plenty of space */
        SMB_ASSERT(result != NULL);