mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
[Core] Fix the null char in truncated value returned by switch_b64_decode
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Seven Du <seven@signalwire.com>
|
||||
*
|
||||
* Windy Wang <xiaofengcanyuexp@163.com>
|
||||
*
|
||||
* switch_utils.c -- tests switch_utils
|
||||
*
|
||||
@@ -63,6 +63,24 @@ FST_TEST_BEGIN(benchmark)
|
||||
}
|
||||
FST_TEST_END()
|
||||
|
||||
FST_TEST_BEGIN(b64)
|
||||
{
|
||||
char *str = "ABC";
|
||||
unsigned char b64_str[6];
|
||||
char decoded_str[4];
|
||||
switch_status_t status = switch_b64_encode((unsigned char *)str, strlen(str), b64_str, sizeof(b64_str));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "b64_str: %s\n", b64_str);
|
||||
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||
fst_check_string_equals((const char *)b64_str, "QUJD");
|
||||
|
||||
switch_size_t size = switch_b64_decode((const char *)b64_str, decoded_str, sizeof(decoded_str));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "decoded_str: %s\n", decoded_str);
|
||||
fst_check_string_equals(decoded_str, str);
|
||||
fst_check(size == 4);
|
||||
}
|
||||
FST_TEST_END()
|
||||
|
||||
|
||||
FST_SUITE_END()
|
||||
|
||||
FST_MINCORE_END()
|
||||
|
Reference in New Issue
Block a user