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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
From 524ee5fa925cc40ff72ac79769f4c7e3f62e5092 Mon Sep 17 00:00:00 2001
From: Elena, Reshetova <elena.reshetova@intel.com>
Date: Mon, 20 Feb 2012 15:50:55 +0200
Subject: [PATCH] Fix for rpmio base64 handling
---
rpmio/base64.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/rpmio/base64.c b/rpmio/base64.c
index 6b006e1..3ebf2a5 100644
--- a/rpmio/base64.c
+++ b/rpmio/base64.c
@@ -104,7 +104,7 @@ static int base64_decode_value(unsigned char value_in)
{
static const int decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,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,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
value_in -= 43;
- if (value_in > sizeof(decoding)/sizeof(int))
+ if (value_in >= sizeof(decoding)/sizeof(int))
return -1;
return decoding[value_in];
}
@@ -165,6 +165,7 @@ int b64decode(const char *in, void **out, size_t *outlen)
{
size_t outcnt = 0;
const char *inptr = in;
+ char *outptr;
*out = NULL;
@@ -189,12 +190,13 @@ int b64decode(const char *in, void **out, size_t *outlen)
outcnt = (outcnt / 4) * 3;
- *out = malloc(outcnt + 1); /* base64_decode_block can write one extra character */
+ *out = outptr = malloc(outcnt + 2); /* base64_decode_block can write one extra character, reserve one more for null termination */
if (*out == NULL)
return 4;
*outlen = base64_decode_block(in, inptr - in, *out);
+ outptr[*outlen] = '\0'; /* null terminate */
return 0;
}
--
1.7.4.1
|