Skip to content

Commit ec27d57

Browse files
committed
slightly improve base64 encoding
* ensure base64 encode in&out buffers aren't the same * allow calling any of the encode functions with `out` being a NULL-pointer, to be able to determine the size for storing the output. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent a24af5f commit ec27d57

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/misc/base64/base64_encode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ static int s_base64_encode_internal(const unsigned char *in, unsigned long in
3737
unsigned long i, len2, leven, linelen;
3838
char *p;
3939

40-
LTC_ARGCHK(in != NULL);
41-
LTC_ARGCHK(out != NULL);
4240
LTC_ARGCHK(outlen != NULL);
4341

4442
linelen = (mode & ssh) ? 72 : 64;
@@ -54,6 +52,14 @@ static int s_base64_encode_internal(const unsigned char *in, unsigned long in
5452
*outlen = len2 + 1;
5553
return CRYPT_BUFFER_OVERFLOW;
5654
}
55+
56+
LTC_ARGCHK(in != NULL);
57+
LTC_ARGCHK(out != NULL);
58+
59+
if ((void*)in == out) {
60+
return CRYPT_INVALID_ARG;
61+
}
62+
5763
p = out;
5864
leven = 3*(inlen / 3);
5965
for (i = 0; i < leven; i += 3) {

0 commit comments

Comments
 (0)