From aed693b9e5123361b536614f4f7d441aecffd82c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 May 2013 19:39:02 -0500 Subject: [PATCH] FS-5436 --resolve --- src/switch_utils.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/switch_utils.c b/src/switch_utils.c index 2141369c62..146e34d6fc 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -666,6 +666,9 @@ SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size while (l >= 6) { out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64]; + if (bytes >= olen - 1) { + goto end; + } if (++y != 72) { continue; } @@ -678,11 +681,15 @@ SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64]; } if (l != 0) { - while (l < 6) { + while (l < 6 && bytes < olen - 1) { out[bytes++] = '=', l += 2; } } + end: + + out[bytes] = '\0'; + return SWITCH_STATUS_SUCCESS; }