From d1115ed0c129614192b9c4e68e7b81b52e08ea4f Mon Sep 17 00:00:00 2001
From: Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
Date: Mon, 23 Sep 2024 16:22:05 +0200
Subject: [PATCH] Align with new code-analysis docker image

---
 .gitlab-ci.yml                    | 12 ++++--------
 gitlab-ci/compile.sh              |  7 -------
 gitlab-ci/install-dependencies.sh | 10 ++++++++++
 gitlab-ci/shared.sh               | 14 ++------------
 src/packetcapture.c               | 11 ++++++-----
 5 files changed, 22 insertions(+), 32 deletions(-)
 delete mode 100755 gitlab-ci/compile.sh
 create mode 100755 gitlab-ci/install-dependencies.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 51d6ec4..526f491 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,15 +1,11 @@
+variables:
+  SOURCE_FOLDER: "src"
+
 include:
   - project: 'iopsys/gitlab-ci-pipeline'
     file: '/static-code-analysis.yml'
-    ref: '0.32'
+    ref: '1.2'
 
 stages:
     - static_code_analysis
 
-variables:
-  DEBUG: 'TRUE'
-  SOURCE_FOLDER: "./src"
-  FLAWFINDER_OPTIONS: "-m 4 --error-level=5"
-  CPPCHECK_OPTIONS: "--enable=all --error-exitcode=1"
-  COMPILE: "./gitlab-ci/compile.sh"
-
diff --git a/gitlab-ci/compile.sh b/gitlab-ci/compile.sh
deleted file mode 100755
index 7e12f5f..0000000
--- a/gitlab-ci/compile.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-source ./gitlab-ci/shared.sh
-
-install_bbfd
-
-exec_cmd_verbose make -C ./src
diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh
new file mode 100755
index 0000000..bb1c6a9
--- /dev/null
+++ b/gitlab-ci/install-dependencies.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+echo "Install dependencies for functional test"
+pwd
+
+source ./gitlab-ci/shared.sh
+
+# install bbfdm
+install_bbfdm
+
diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh
index f4b3349..dc60651 100644
--- a/gitlab-ci/shared.sh
+++ b/gitlab-ci/shared.sh
@@ -11,18 +11,9 @@ function exec_cmd()
 	fi
 }
 
-function exec_cmd_verbose()
+function install_bbfdm()
 {
-	echo "executing $@"
-	if ! $@; then
-		echo "Failed to execute $@"
-		exit 1
-	fi
-}
-
-function install_bbfd()
-{
-	[ -d "/opt/dev/bbfdm" ] && rm -rf /opt/dev/bbfdm
+	[ -d "/opt/dev/bbfdm" ] && return 0
 
 	if [ -n "${BBFDM_BRANCH}" ]; then
 		exec_cmd git clone -b ${BBFDM_BRANCH} https://dev.iopsys.eu/bbf/bbfdm.git /opt/dev/bbfdm
@@ -33,5 +24,4 @@ function install_bbfd()
 	cd /opt/dev/bbfdm
 	./gitlab-ci/install-dependencies.sh install
 	./gitlab-ci/setup.sh install
-	cd -
 }
diff --git a/src/packetcapture.c b/src/packetcapture.c
index 3f2a43b..640736b 100644
--- a/src/packetcapture.c
+++ b/src/packetcapture.c
@@ -33,10 +33,11 @@ static int browsePacketCaptureResultInst(struct dmctx *dmctx, DMNODE *parent_nod
 
 static void stop_packetcapture_diagnostics(void)
 {
-	char cmd[256] = {0};
+	char output[256] = {0}, cmd[256] = {0};
 
 	snprintf(cmd, sizeof(cmd), "sh %s '{\"proto\":\"both_proto\",\"cancel\":\"1\"}'", PACKET_CAPTURE_DIAGNOSTIC_PATH);
-	system(cmd);
+
+	run_cmd(cmd, output, sizeof(output));
 }
 
 /*************************************************************
@@ -90,14 +91,14 @@ int operate_Device_packetCapture(char *refparam, struct dmctx *ctx, void *data,
 	if (format[0] != '\0' && bbfdm_validate_string(ctx, format, -1, -1, allowed_format, NULL))
 		return USP_FAULT_INVALID_ARGUMENT;
 
-	char *duration = dmjson_get_value((json_object *)value, 1, "Duration");
+	const char *duration = dmjson_get_value((json_object *)value, 1, "Duration");
 	if (duration[0] != '\0') {
 		if (bbfdm_validate_unsignedInt(ctx, duration, RANGE_ARGS{{"1", NULL}}, 1))
 			return USP_FAULT_INVALID_ARGUMENT;
 	} else
 		duration = "1";
 
-	char *pack_count = dmjson_get_value((json_object *)value, 1, "PacketCount");
+	const char *pack_count = dmjson_get_value((json_object *)value, 1, "PacketCount");
 	if (pack_count[0] != '\0') {
 		if (bbfdm_validate_unsignedInt(ctx, pack_count, RANGE_ARGS{{0, NULL}}, 1))
 			return USP_FAULT_INVALID_ARGUMENT;
@@ -354,7 +355,7 @@ static int set_PacketCapture_Username(char *refparam, struct dmctx *ctx, void *d
 
 static int get_PacketCapture_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
 {
-	*value = "";
+	*value = dmstrdup("");
 	return 0;
 }
 
-- 
GitLab