From a1ec31a74f05cc172e8d839236d8a18a30024356 Mon Sep 17 00:00:00 2001 From: WangFengTu Date: Tue, 12 May 2020 06:47:05 -0400 Subject: [PATCH] fix bug of base64 encode and add testcase for pull image Signed-off-by: WangFengTu --- CI/test_cases/basic_cases/helpers.bash | 1 + CI/test_cases/basic_cases/registry.bash | 50 +++++++++++++++++++++++++ src/cutils/utils_base64.c | 27 ++++++++++--- src/image/oci/registry/registry.c | 2 +- 4 files changed, 73 insertions(+), 7 deletions(-) create mode 100755 CI/test_cases/basic_cases/registry.bash diff --git a/CI/test_cases/basic_cases/helpers.bash b/CI/test_cases/basic_cases/helpers.bash index 73852f9..27bd4b5 100755 --- a/CI/test_cases/basic_cases/helpers.bash +++ b/CI/test_cases/basic_cases/helpers.bash @@ -22,6 +22,7 @@ declare -a lines # Root directory of integration tests. INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")") LCR_ROOT_PATH="/var/lib/isulad/engines/lcr" +ISUALD_LOG="/var/lib/isulad/isulad.log" function cut_output_lines() { message=`$@ 2>&1` diff --git a/CI/test_cases/basic_cases/registry.bash b/CI/test_cases/basic_cases/registry.bash new file mode 100755 index 0000000..c48555f --- /dev/null +++ b/CI/test_cases/basic_cases/registry.bash @@ -0,0 +1,50 @@ +#!/bin/bash +# +# attributes: isulad inheritance version +# concurrent: YES +# spend time: 1 + +####################################################################### +##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. +# - iSulad licensed under the Mulan PSL v2. +# - You can use this software according to the terms and conditions of the Mulan PSL v2. +# - You may obtain a copy of Mulan PSL v2 at: +# - http://license.coscl.org.cn/MulanPSL2 +# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# - PURPOSE. +# - See the Mulan PSL v2 for more details. +##- @Description:CI +##- @Author: wangfengtu +##- @Create: 2020-05-12 +####################################################################### + +curr_path=$(dirname $(readlink -f "$0")) +data_path=$(realpath $curr_path/../data) +source ./helpers.bash + +function isula_pull() +{ + isula pull busybox + fn_check_eq "$?" "0" "isula pull busybox" + + isula inspect busybox + fn_check_eq "$?" "0" "isula inspect busybox" +} + +function do_test_t() +{ + isula_pull + + return $TC_RET_T +} + +ret=0 + +do_test_t +if [ $? -ne 0 ];then + cat $ISUALD_LOG + let "ret=$ret + 1" +fi + +show_result $ret "basic pull" diff --git a/src/cutils/utils_base64.c b/src/cutils/utils_base64.c index 314ff5d..fdb9915 100644 --- a/src/cutils/utils_base64.c +++ b/src/cutils/utils_base64.c @@ -31,6 +31,8 @@ size_t util_base64_encode(unsigned char *bytes, size_t len, char *out, size_t ou int ret = 0; int bio_ret = 0; BUF_MEM *pmem = NULL; + size_t i = 0; + size_t count = 0; if (bytes == NULL || len == 0 || out == NULL || out_len < util_base64_encode_len(len)) { ERROR("Invalid param for encoding base64, input length %zu, out length %zu", len, out_len); @@ -66,16 +68,29 @@ size_t util_base64_encode(unsigned char *bytes, size_t len, char *out, size_t ou } (void)BIO_get_mem_ptr(io, &pmem); - if (pmem->length > out_len) { - ERROR("result length larger than output length, result length %zu, input length %zu, output length %zu", - pmem->length, len, out_len); + // BIO_write append '\n' if every 76 chars have be output, so we need to strip them. + for (i = 0; i < pmem->length; i++) { + if (pmem->data[i] == '\n') { + continue; + } + if (count + 1 == out_len) { + ERROR("result length larger than output length, result length %zu, input length %zu, output length %zu", + pmem->length, len, out_len); + ret = -1; + goto out; + } + out[count] = pmem->data[i]; + count++; + } + + if (count == 0) { + ERROR("Base64 encode failed, result count is zero"); ret = -1; goto out; } - (void)memcpy(out, pmem->data, pmem->length); - out[pmem->length - 1] = 0; - result_len = pmem->length; + out[count] = 0; + result_len = count + 1; out: diff --git a/src/image/oci/registry/registry.c b/src/image/oci/registry/registry.c index 53c90d5..73916c9 100644 --- a/src/image/oci/registry/registry.c +++ b/src/image/oci/registry/registry.c @@ -1192,7 +1192,7 @@ static int do_fetch(thread_fetch_info *info) if (cache == NULL) { ret = fetch_one_layer(info); if (ret != 0) { - ERROR("failed to start thread to fetch layer %d", (int)info->index); + ERROR("failed to to fetch layer %d", (int)info->index); goto out; } } -- GitLab