]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
base64: better alloc size
authorDaniel Stenberg <daniel@haxx.se>
Sat, 3 Dec 2022 23:07:52 +0000 (00:07 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 5 Dec 2022 07:11:24 +0000 (08:11 +0100)
The previous algorithm allocated more bytes than necessary.

Suggested-by: xtonik on github
Fixes #10024
Closes #10025

lib/base64.c

index 52654c2bc334c16a572758727dc04b20b2f2110c..2760e7bbe856f0307ac32a5b32d8351a189d3a17 100644 (file)
@@ -192,7 +192,7 @@ static CURLcode base64_encode(const char *table64,
     return CURLE_OUT_OF_MEMORY;
 #endif
 
-  base64data = output = malloc(insize * 4 / 3 + 4);
+  base64data = output = malloc((insize + 2) / 3 * 4 + 1);
   if(!output)
     return CURLE_OUT_OF_MEMORY;