!271 [sync] PR-269: add gazelle fuzz & add log message when wait for connecting to ltran

From: @openeuler-sync-bot 
Reviewed-by: @jiangheng12 
Signed-off-by: @jiangheng12
This commit is contained in:
openeuler-ci-bot 2023-02-01 08:37:03 +00:00 committed by Gitee
commit de74674d4b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 575 additions and 1 deletions

View File

@ -0,0 +1,24 @@
From eb3f797f679605c26355aea152b249dfd3852786 Mon Sep 17 00:00:00 2001
From: kircher <majun65@huawei.com>
Date: Sun, 29 Jan 2023 21:02:33 +0800
Subject: [PATCH] add log message when wait for connecting to ltran
---
src/lstack/core/lstack_control_plane.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c
index bf55df5..bc2c55d 100644
--- a/src/lstack/core/lstack_control_plane.c
+++ b/src/lstack/core/lstack_control_plane.c
@@ -97,6 +97,7 @@ static int32_t connect_to_ltran(int32_t times, int32_t interval)
return sockfd;
}
+ LSTACK_LOG(INFO, LSTACK, "wait for connecting to ltran\n");
int32_t ret = posix_api->connect_fn(sockfd, (struct sockaddr*)&address, sizeof(address));
if (ret == 0) {
return sockfd;
--
2.33.0

544
0184-add-gazelle-fuzz.patch Normal file
View File

@ -0,0 +1,544 @@
From b8a055fd42c14f3934c80d8eff98c6c5ac5246f2 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Tue, 31 Jan 2023 14:23:55 +0800
Subject: [PATCH] add gazelle fuzz
---
test/fuzz/CMakeLists.txt | 22 ++++
test/fuzz/fuzz.dict | 1 +
test/fuzz/fuzz.sh | 117 ++++++++++++++++++
test/fuzz/lstack_config/CMakeLists.txt | 25 ++++
test/fuzz/lstack_config/lstack.conf | 17 +++
test/fuzz/lstack_config/lstack_config_fuzz.c | 106 ++++++++++++++++
test/fuzz/ltran_config/CMakeLists.txt | 23 ++++
test/fuzz/ltran_config/corpus/sample_data | 1 +
.../ltran_config/dict/ltran_config_fuzz.dict | 1 +
test/fuzz/ltran_config/ltran.conf | 26 ++++
test/fuzz/ltran_config/ltran_config_fuzz.c | 106 ++++++++++++++++
11 files changed, 445 insertions(+)
create mode 100644 test/fuzz/CMakeLists.txt
create mode 100644 test/fuzz/fuzz.dict
create mode 100644 test/fuzz/fuzz.sh
create mode 100644 test/fuzz/lstack_config/CMakeLists.txt
create mode 100644 test/fuzz/lstack_config/lstack.conf
create mode 100644 test/fuzz/lstack_config/lstack_config_fuzz.c
create mode 100644 test/fuzz/ltran_config/CMakeLists.txt
create mode 100644 test/fuzz/ltran_config/corpus/sample_data
create mode 100644 test/fuzz/ltran_config/dict/ltran_config_fuzz.dict
create mode 100644 test/fuzz/ltran_config/ltran.conf
create mode 100644 test/fuzz/ltran_config/ltran_config_fuzz.c
diff --git a/test/fuzz/CMakeLists.txt b/test/fuzz/CMakeLists.txt
new file mode 100644
index 0000000..6d0f41e
--- /dev/null
+++ b/test/fuzz/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is 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.
+
+cmake_minimum_required(VERSION 3.12.1)
+SET(CMAKE_C_COMPILER "clang")
+project(gazelle_test)
+set(COMMON_PATH ${PROJECT_SOURCE_DIR}/../../src/common)
+add_library(common_obj OBJECT ${COMMON_PATH}/gazelle_parse_config.c)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -fsanitize=fuzzer,address -g")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -fprofile-arcs -ftest-coverage -fsanitize=fuzzer")
+# testcase
+add_subdirectory(ltran_config)
+add_subdirectory(lstack_config)
+
diff --git a/test/fuzz/fuzz.dict b/test/fuzz/fuzz.dict
new file mode 100644
index 0000000..8b8441b
--- /dev/null
+++ b/test/fuzz/fuzz.dict
@@ -0,0 +1 @@
+"test"
diff --git a/test/fuzz/fuzz.sh b/test/fuzz/fuzz.sh
new file mode 100644
index 0000000..c941776
--- /dev/null
+++ b/test/fuzz/fuzz.sh
@@ -0,0 +1,117 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is 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.
+
+
+function generate_coverage()
+{
+ local target_dir=$(dirname `pwd`)
+ echo ------------------ generate coverage begin --------------
+ if [ -d ${target_dir}/build/coverage/html ]; then
+ rm -rf ${target_dir}/build/coverage/html
+ fi
+ mkdir -p ${target_dir}/build/coverage/html
+ if [ x"${COVER_FILE}" = x"" ]; then
+ LCOV_CMD="-d ${target_dir}"
+ else
+ GCDAS=`find ${target_dir} -name "${COVER_FILE}.gcda"`
+ if [ $? != 0 ]; then
+ echo -e "\033[;31mnot find\033[0m ${COVER_FILE}.gcda"
+ exit 1
+ fi
+
+ for GCDA in ${GCDAS}; do
+ TMP_STR=" -d ${GCDA}";
+ LCOV_CMD="${LCOV_CMD} ${TMP_STR}";
+ done
+ fi
+
+ # lcov -c ${LCOV_CMD} -o ${target_dir}/build/coverage/html/coverage.info --exclude '*_test.c' --include '*.c' --include '*.cpp' --include '*.cc' --rc lcov_branch_coverage=1 --ignore-errors gcov --ignore-errors source --ignore-errors graph
+ lcov -c ${LCOV_CMD} -b $(dirname $(pwd)) --exclude '*test*' --exclude '*.h' -o ${target_dir}/build/coverage/html/coverage.info --rc lcov_branch_coverage=1 --ignore-errors gcov --ignore-errors source --ignore-errors graph
+ if [ $? != 0 ]; then
+ echo -e "lcov generate coverage.info \033[;31mfail\033[0m."
+ exit 1
+ fi
+
+ genhtml ${target_dir}/build/coverage/html/coverage.info -o ${target_dir}/build/coverage/html --branch-coverage --rc lcov_branch_coverage=1 -s --legend --ignore-errors source
+ if [ $? != 0 ]; then
+ echo -e "genhtml \033[;31mfail\033[0m."
+ exit 1
+ fi
+ chmod 755 -R ${target_dir}/build/coverage/html
+ echo ------------------ generate coverage end ----------------
+}
+
+LIB_FUZZING_ENGINE="/lib64/libFuzzer.a"
+FUZZ_OPTION="../corpus -dict=../fuzz.dict -runs=30000000 -max_total_time=10800 -artifact_prefix=fuzz-"
+
+if [ ! -f $LIB_FUZZING_ENGINE ]; then
+ echo "$LIB_FUZZING_ENGINE not exist, pls check"
+ exit 1
+fi
+
+rm -rf build
+mkdir build
+cd build
+
+sed 's/ read(/ s_read(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ write/ s_write/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ fcntl(/ s_fcntl(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ socket(/ s_socket(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ close(/ s_close(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ write(/ s_write(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ send(/ s_send(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ sendmsg(/ s_sendmsg(/' -i ../../../src/lstack/api/lstack_wrap.c
+
+cmake ..
+make -j
+
+export ASAN_OPTIONS=halt_on_error=0
+
+usage()
+{
+ echo "Usage: fuzz.sh [ltran_config | lstack_config | lstack_api]"
+}
+
+case "$1" in
+ ltran_config)
+ ./ltran_config_fuzz $FUZZ_OPTION;;
+ lstack_config)
+ ./lstack_config_fuzz $FUZZ_OPTION;;
+ lstack_api)
+ ./lstack_api_fuzz $FUZZ_OPTION;;
+ *)
+ echo "param is wrong"
+ usage; exit 0;;
+esac
+
+# 运行fuzz测试程序
+
+# 查找crash文件
+echo "############# Fuzz Result #############"
+crash=`find -name "*-crash-*"`
+if [ x"$crash" != x"" ]; then
+ echo "find bugs while fuzzing, pls check <*-crash-*> file"
+ find -name "*-crash-*"
+ echo "fuzz failed"
+else
+ echo "all fuzz success."
+fi
+
+generate_coverage
+
+sed 's/ s_read/ read/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_write/ write/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_fcntl(/ fcntl(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_socket(/ socket(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_close(/ close(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_write(/ write(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_send(/ send(/' -i ../../../src/lstack/api/lstack_wrap.c
+sed 's/ s_sendmsg(/ sendmsg(/' -i ../../../src/lstack/api/lstack_wrap.c
diff --git a/test/fuzz/lstack_config/CMakeLists.txt b/test/fuzz/lstack_config/CMakeLists.txt
new file mode 100644
index 0000000..6f306a2
--- /dev/null
+++ b/test/fuzz/lstack_config/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is 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.
+
+cmake_minimum_required(VERSION 3.12.1)
+project(gazelle_test)
+
+set(SDK_PATH /usr/include/dpdk)
+set(LWIP_PATH /usr/include/lwip)
+set(LIB_PATH ${PROJECT_SOURCE_DIR}/../../../src/lstack/include)
+set(SRC_PATH ${PROJECT_SOURCE_DIR}/../../../src/lstack/core)
+add_executable(lstack_config_fuzz lstack_config_fuzz.c ${SRC_PATH}/lstack_cfg.c)
+
+target_compile_options(lstack_config_fuzz PRIVATE -DUSE_LIBOS_MEM)
+
+SET(EXECUTABLE_OUTPUT_PATH ../)
+
+target_include_directories(lstack_config_fuzz PRIVATE ${LIB_PATH} ${SDK_PATH} ${LWIP_PATH} ${COMMON_PATH})
+target_link_libraries(lstack_config_fuzz PRIVATE pthread config securec liblwip.a common_obj)
diff --git a/test/fuzz/lstack_config/lstack.conf b/test/fuzz/lstack_config/lstack.conf
new file mode 100644
index 0000000..3851c3d
--- /dev/null
+++ b/test/fuzz/lstack_config/lstack.conf
@@ -0,0 +1,17 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is 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.
+
+dpdk_args=["-l", "2", "--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-2M", "--proc-type", "primary"]
+num_cpus=1
+
+host_addr="192.168.1.10"
+mask_addr="255.255.255.0"
+gateway_addr="192.168.1.1"
+devices="aa:bb:cc:dd:ee:ff"
diff --git a/test/fuzz/lstack_config/lstack_config_fuzz.c b/test/fuzz/lstack_config/lstack_config_fuzz.c
new file mode 100644
index 0000000..cd69f5c
--- /dev/null
+++ b/test/fuzz/lstack_config/lstack_config_fuzz.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <securec.h>
+
+#include "lstack_cfg.h"
+#include "lstack_protocol_stack.h"
+
+#define MAX_CMD_LEN 1024
+#define MAX_STR_LEN 20
+
+#define FUZZ_LSTACK_CONF_PATH_TMP "./lstack.conf"
+#define FUZZ_LSTACK_CONF_PATH "/etc/gazelle/lstack.conf"
+#define FUZZ_LSTACK_CONF_PATH_BAK "/etc/gazelle/lstack.conf.bak"
+
+void lwip_set_host_ipv4(unsigned int ipv4)
+{
+ return;
+}
+
+int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
+{
+ return 0;
+}
+
+static struct protocol_stack_group g_stack_group = {0};
+struct protocol_stack_group *get_protocol_stack_group(void)
+{
+ return &g_stack_group;
+}
+
+int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
+{
+ char str[MAX_STR_LEN + 1] = {0};
+ char cmd[MAX_CMD_LEN + 1] = {0};
+ char *sed_str[] = {"dpdk_args", "host_addr", "mask_addr", "gateway_addr", "devices"};
+ static int index = 0;
+ struct cfg_params *cfg_params = get_global_cfg_params();
+
+ if (data == NULL) {
+ return 0;
+ }
+
+ system("mkdir -p /etc/gazelle");
+
+ if (sprintf_s(cmd, MAX_CMD_LEN, "cp -f %s %s; cp -f %s %s", FUZZ_LSTACK_CONF_PATH, FUZZ_LSTACK_CONF_PATH_BAK,
+ FUZZ_LSTACK_CONF_PATH_TMP, FUZZ_LSTACK_CONF_PATH) < 0) {
+ return -1;
+ }
+ system(cmd);
+
+ for (int i = 0; i < MAX_STR_LEN && i < size; i++) {
+ if (((data[i] >= 'a') && (data[i] <= 'z')) ||
+ ((data[i] >= 'A') && (data[i] <= 'Z')) ||
+ ((data[i] >= '0') && (data[i] <= '9'))) {
+ str[i] = data[i];
+ } else {
+ str[i] = ' ';
+ }
+ }
+ index = (index + 1) % 5; /* 5:匹配字符串总数 */
+ if (sprintf_s(cmd, MAX_CMD_LEN, "sed -i '/%s/s/\".*\"/\"%s\"/' %s",
+ sed_str[index], str, FUZZ_LSTACK_CONF_PATH) < 0) {
+ return -1;
+ }
+ system(cmd);
+
+ memset_s(cfg_params, sizeof(struct cfg_params), 0, sizeof(*cfg_params));
+
+ // test parse config
+ (void)cfg_init();
+
+ // free memory if used
+ if (cfg_params->dpdk_argv) {
+ if (cfg_params->dpdk_argv[0] != NULL) {
+ free(cfg_params->dpdk_argv[0]);
+ }
+ for (int i = 0; i < cfg_params->dpdk_argc; i++) {
+ if (cfg_params->dpdk_argv[i + 1] != NULL) {
+ free(cfg_params->dpdk_argv[i + 1]);
+ }
+ }
+ free(cfg_params->dpdk_argv);
+ }
+
+ if (sprintf_s(cmd, MAX_CMD_LEN, "cp -f %s %s;rm -f %s", FUZZ_LSTACK_CONF_PATH_BAK, FUZZ_LSTACK_CONF_PATH,
+ FUZZ_LSTACK_CONF_PATH_BAK) < 0) {
+ return -1;
+ }
+ system(cmd);
+ return 0;
+}
+
diff --git a/test/fuzz/ltran_config/CMakeLists.txt b/test/fuzz/ltran_config/CMakeLists.txt
new file mode 100644
index 0000000..0c4614c
--- /dev/null
+++ b/test/fuzz/ltran_config/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is 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.
+
+cmake_minimum_required(VERSION 3.12.1)
+project(gazelle_test)
+
+set(SDK_PATH /usr/include/dpdk)
+set(LIB_PATH ${PROJECT_SOURCE_DIR}/../../../src/ltran)
+set(SRC_PATH ${PROJECT_SOURCE_DIR}/../../../src/ltran)
+
+SET(EXECUTABLE_OUTPUT_PATH ../)
+
+add_executable(ltran_config_fuzz ltran_config_fuzz.c ${SRC_PATH}/ltran_param.c ${SRC_PATH}/ltran_errno.c)
+
+target_include_directories(ltran_config_fuzz PRIVATE ${LIB_PATH} ${SDK_PATH} ${COMMON_PATH})
+target_link_libraries(ltran_config_fuzz PRIVATE securec pthread config common_obj)
diff --git a/test/fuzz/ltran_config/corpus/sample_data b/test/fuzz/ltran_config/corpus/sample_data
new file mode 100644
index 0000000..72943a1
--- /dev/null
+++ b/test/fuzz/ltran_config/corpus/sample_data
@@ -0,0 +1 @@
+aaa
diff --git a/test/fuzz/ltran_config/dict/ltran_config_fuzz.dict b/test/fuzz/ltran_config/dict/ltran_config_fuzz.dict
new file mode 100644
index 0000000..8b8441b
--- /dev/null
+++ b/test/fuzz/ltran_config/dict/ltran_config_fuzz.dict
@@ -0,0 +1 @@
+"test"
diff --git a/test/fuzz/ltran_config/ltran.conf b/test/fuzz/ltran_config/ltran.conf
new file mode 100644
index 0000000..019b107
--- /dev/null
+++ b/test/fuzz/ltran_config/ltran.conf
@@ -0,0 +1,26 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is 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.
+
+forward_kit="dpdk"
+forward_kit_args="-l 0,1 --socket-mem 1024,0,0,0 --huge-dir /mnt/hugepages-ltran --proc-type primary --legacy-mem --map-perfect --syslog daemon"
+
+kni_switch=0
+
+dispatch_max_clients=30
+dispatch_subnet="192.168.1.0"
+dispatch_subnet_length=8
+
+bond_mode=1
+bond_mtu=1500
+bond_miimon=100
+bond_macs="aa:bb:cc:dd:ee:ff"
+bond_ports="0x1"
+
+tcp_conn_scan_interval=10
diff --git a/test/fuzz/ltran_config/ltran_config_fuzz.c b/test/fuzz/ltran_config/ltran_config_fuzz.c
new file mode 100644
index 0000000..7d27125
--- /dev/null
+++ b/test/fuzz/ltran_config/ltran_config_fuzz.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "ltran_base.h"
+#include "ltran_param.h"
+
+#define MAX_CMD_LEN 1024
+#define MAX_STR_LEN 20
+
+#define FUZZ_LTRAN_CONF_PATH "./ltran.conf"
+#define FUZZ_LTRAN_CONF_PATH_TMP "./ltran_tmp.conf"
+
+int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
+{
+ return 0;
+}
+
+void restore_conf_file(const unsigned char *data, size_t size)
+{
+ int ret;
+ char cmd[MAX_CMD_LEN];
+ char str[MAX_STR_LEN + 1] = {0};
+ char *sed_str[] = {"forward_kit_args", "kni_switch", "dispatch_subnet", "dispatch_subnet_length",
+ "dispatch_max_clients", "bond_mode", "bond_miimon", "bond_mtu", "bond_ports", "bond_macs",
+ "tcp_conn_scan_interval"};
+ static int index = 0;
+
+ // reset conf file
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "rm -f %s", FUZZ_LTRAN_CONF_PATH_TMP);
+ if (ret < 0) {
+ return;
+ }
+ system(cmd);
+
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "cp -f %s %s", FUZZ_LTRAN_CONF_PATH, FUZZ_LTRAN_CONF_PATH_TMP);
+ if (ret < 0) {
+ return;
+ }
+ system(cmd);
+
+ for (int i = 0; i < MAX_STR_LEN && i < size; i++) {
+ if (((data[i] >= 'a') && (data[i] <= 'z')) ||
+ ((data[i] >= 'A') && (data[i] <= 'Z')) ||
+ ((data[i] >= '0') && (data[i] <= '9'))) {
+ str[i] = data[i];
+ } else {
+ str[i] = ' ';
+ }
+ }
+ index = (index + 1) % 11; /* 11:匹配字符串总数 */
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "sed -i '/%s/s/= .*/= \"%s\"/' %s",
+ sed_str[index], str, FUZZ_LTRAN_CONF_PATH_TMP);
+ if (ret < 0) {
+ return;
+ }
+ system(cmd);
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "sed -i '/%s/s/= [0-9].*/= %s/' %s",
+ sed_str[index], str, FUZZ_LTRAN_CONF_PATH_TMP);
+ if (ret < 0) {
+ return;
+ }
+ system(cmd);
+}
+
+int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
+{
+ struct ltran_config ltran_config;
+
+ if (data == NULL) {
+ return 0;
+ }
+
+ restore_conf_file(data, size);
+ (void)memset_s(&ltran_config, sizeof(struct ltran_config), 0, sizeof(struct ltran_config));
+
+ // test parse DEFAULT_LTRAN_CONF_PATH_TMP
+ (void)parse_config_file_args(FUZZ_LTRAN_CONF_PATH_TMP, &ltran_config);
+ // free memory if used
+ for (int i = 0; i < ltran_config.dpdk.dpdk_argc; i++) {
+ if ((ltran_config.dpdk.dpdk_argv != NULL) &&
+ (ltran_config.dpdk.dpdk_argv[i] != NULL)) {
+ free(ltran_config.dpdk.dpdk_argv[i]);
+ ltran_config.dpdk.dpdk_argv[i] != NULL;
+ }
+ }
+ if (ltran_config.dpdk.dpdk_argv != NULL) {
+ free(ltran_config.dpdk.dpdk_argv);
+ ltran_config.dpdk.dpdk_argv = NULL;
+ }
+ return 0;
+}
+
--
2.33.0

View File

@ -2,7 +2,7 @@
Name: gazelle
Version: 1.0.1
Release: 45
Release: 46
Summary: gazelle is a high performance user-mode stack
License: MulanPSL-2.0
URL: https://gitee.com/openeuler/gazelle
@ -197,6 +197,8 @@ Patch9179: 0179-revert-expand-recv-data-buff.patch
Patch9180: 0180-add-the-suggestion-of-using-the-u-parameter-when-the.patch
Patch9181: 0181-move-control_client_thread-creation-after-control_in.patch
Patch9182: 0182-add-ret-check-in-pthread_create-and-fix-example-bug.patch
Patch9183: 0183-add-log-message-when-wait-for-connecting-to-ltran.patch
Patch9184: 0184-add-gazelle-fuzz.patch
%description
%{name} is a high performance user-mode stack.
@ -237,6 +239,10 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b
%config(noreplace) %{conf_path}/ltran.conf
%changelog
* Tue Jan 31 2023 kircher <majun65@huawei.com> - 1.0.1-46
- add gazelle fuzz
- add log message when wait for connecting to ltran
* Mon Jan 16 2023 kircher <majun65@huawei.com> - 1.0.1-45
- add ret check in pthread_create and fix example bug
- move control_client_thread creation after control_in and dpdk_skip_nic_init