From c50b1deb62bc931f350b799a65a5ac3aa88352dd Mon Sep 17 00:00:00 2001
From: Vivek Kumar Dutta <vivek.dutta@iopsys.eu>
Date: Wed, 20 Nov 2024 13:41:21 +0000
Subject: [PATCH] Switch to new code-analysis image

---
 .gitlab-ci.yml                    | 12 +++++-------
 gitlab-ci/install-dependencies.sh |  6 ++++--
 src/datamodel.c                   |  7 +------
 src/swmod.h                       |  4 ++--
 src/swmod_common.h                |  6 +++---
 src/swmod_lxc.c                   |  2 +-
 src/tools.c                       | 25 +++++++++++--------------
 7 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 79530b0..f795bab 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,16 +1,14 @@
 variables:
-  DOCKER_DRIVER: overlay2
-  BUILDX_VERSION: "v0.10.4"
-  BUILDX_ARCH: "linux-amd64"
-  DEBUG: 'TRUE'
+  #DOCKER_DRIVER: overlay2
+  #BUILDX_VERSION: "v0.10.4"
+  #BUILDX_ARCH: "linux-amd64"
   SOURCE_FOLDER: "./src"
-  FLAWFINDER_OPTIONS: "-m 4 --error-level=5"
-  CPPCHECK_OPTIONS: " --enable=all --error-exitcode=1 -DSWMOD_HOST_IS_EXECENV -DSWMOD_LXC --suppress=unusedFunction"
+  CPPCHECK_OPTIONS: "--suppress=cert-MSC24-C --suppress=cert-EXP05-C"
 
 include:
   - project: 'iopsys/gitlab-ci-pipeline'
     file: '/static-code-analysis.yml'
-    ref: '0.31'
+    ref: '1.2'
   - project: 'docs/portal2/pipeline-template'
     file: 'MkDocs.gitlab-ci.yml'
     rules:
diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh
index fb6675f..dbde775 100755
--- a/gitlab-ci/install-dependencies.sh
+++ b/gitlab-ci/install-dependencies.sh
@@ -9,5 +9,7 @@ echo "Installing required packages"
 exec_cmd apt update
 exec_cmd apt install -y uuid-dev lxc-dev lxc
 
-echo "Installing datamodel support"
-install_bbfdm
+if [ ! -d "/opt/dev/bbfdm" ]; then
+	echo "Installing datamodel support"
+	install_bbfdm
+fi
diff --git a/src/datamodel.c b/src/datamodel.c
index 4043c64..325036a 100644
--- a/src/datamodel.c
+++ b/src/datamodel.c
@@ -669,13 +669,8 @@ static int get_SoftwareModulesExecutionUnit_ExecEnvLabel(char *refparam, struct
 
 	ee_name = dmjson_get_value(p->json_object, 1, "ee_name");
 	eu_name = dmjson_get_value(p->json_object, 1, "eu_name");
-	if (ee_name == NULL)
-		ee_name = "";
 
-	if (eu_name == NULL)
-		eu_name = "";
-
-	dmasprintf(value, "%.32s%.32s", ee_name, eu_name);
+	dmasprintf(value, "%.32s%.32s", (ee_name)?(ee_name):"", (eu_name)?(eu_name):"");
 	return 0;
 }
 
diff --git a/src/swmod.h b/src/swmod.h
index ae469b2..aa32048 100644
--- a/src/swmod.h
+++ b/src/swmod.h
@@ -63,9 +63,10 @@ typedef struct {
 
 typedef struct ExecUnit {
 	bool eu_exists;
-	char euid[MAX_LEN_65]; //EUID
+	bool autostart;
 	int disk_space; //DiskSpaceInUse
 	int memory_space; //MemoryInUse
+	char euid[MAX_LEN_65]; //EUID
 	char name[MAX_LEN_32]; // //Execution Unit Name
 	char state[MAX_LEN_32]; // //Execution Unit Name
 	char command[MAX_LEN_32]; //Execution Unit Command
@@ -77,7 +78,6 @@ typedef struct ExecUnit {
 	char req_state[MAX_LEN_16];
 	char du_name[MAX_LEN_64]; // //Deployment Unit Name
 	char eu_alias[MAX_LEN_65];
-	bool autostart;
 	char fault_code[MAX_LEN_32];
 } ExecUnit;
 
diff --git a/src/swmod_common.h b/src/swmod_common.h
index e5fad84..1a8306a 100644
--- a/src/swmod_common.h
+++ b/src/swmod_common.h
@@ -28,15 +28,15 @@ enum swmod_du_opration_enum {
 
 typedef struct {
 	time_t start;
+	int operation;
+	unsigned long instance;
+	struct uci_section *section;
 	char env_var[MAX_ENV_VAR_BUFF];
 	char url[2049];
 	char uname[257];
 	char psw[257];
 	char uuid[37];
 	char env_name[32];
-	int operation;
-	unsigned long instance;
-	struct uci_section *section;
 } PkgInfo;
 
 bool memory_available(unsigned long req_kb, const char *dst);
diff --git a/src/swmod_lxc.c b/src/swmod_lxc.c
index 2f626ad..01e6114 100644
--- a/src/swmod_lxc.c
+++ b/src/swmod_lxc.c
@@ -708,7 +708,7 @@ static int lxc_attach_run_cmd(void *args)
 		return 0;
 	}
 
-	pp = popen(cmd, "r");
+	pp = popen(cmd, "r"); // flawfinder: ignore
 	if (pp != NULL) {
 		char line[MAX_LEN_512] = {0};
 
diff --git a/src/tools.c b/src/tools.c
index e3c925e..dd0caee 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -227,12 +227,12 @@ char *generate_duid(bool sysnchronise, int number)
 		char euid_num[8] = {0};
 
 		for (i = 0; i < 3; i++)
-			euid[i] = buf[rand() % div];
+			euid[i] = buf[rand() % div]; //cppcheck-suppress cert-MSC30-c
 		snprintf(euid_num, sizeof(euid_num), "%04d", number);
 		strncat(euid, euid_num, 4);
 	} else {
 		for (i = 0; i < 7; i++)
-			euid[i] = buf[rand() % div];
+			euid[i] = buf[rand() % div]; //cppcheck-suppress cert-MSC30-c
 	}
 	euid[7] = '\0';
 
@@ -261,14 +261,15 @@ int run_cmd(const char *cmd, char *output, size_t out_len)
 	if (cmd == NULL) // null command to run, silently ignore
 		return 0;
 
+	// init the buffer
+	memset(output, 0, out_len);
+
+	pp = popen(cmd, "r"); // flawfinder: ignore
+
 	if (output == NULL || out_len == 0) {
 		return ret;
 	}
 
-	// init the buffer
-	memset(output, 0, out_len);
-
-	pp = popen(cmd, "r");
 	if (pp != NULL) {
 		char line[512] = {0};
 
@@ -288,13 +289,7 @@ int run_cmd(const char *cmd, char *output, size_t out_len)
 /* when command has no output or output is not needed */
 int run_cmd_no_output(const char *cmd)
 {
-	if (cmd == NULL)
-		return 0;
-
-	if (0 != system(cmd))
-		return -1;
-
-	return 0;
+	return run_cmd(cmd, NULL, 0);
 }
 
 int get_env_type(const char *type)
@@ -650,7 +645,7 @@ void swmod_add_ee_in_list(struct list_head *ee_list, ExecEnv_t *ee)
 		PRINT_ERR("Out of memory");
 		return;
 	}
-
+	memset(node, 0, sizeof(ExecEnvNode));
 	memcpy(&node->env, ee, sizeof(ExecEnv_t));
 	INIT_LIST_HEAD(&node->list);
 	list_add_tail(&node->list, ee_list);
@@ -678,6 +673,7 @@ void swmod_add_eu_in_list(struct list_head *eu_list, ExecUnit *eu)
 		return;
 	}
 
+	memset(node, 0, sizeof(EuNode));
 	memcpy(&node->eu, eu, sizeof(ExecUnit));
 	INIT_LIST_HEAD(&node->list);
 	list_add_tail(&node->list, eu_list);
@@ -846,6 +842,7 @@ void buffer_add_line(struct list_head *head, char *entry)
 		return;
 	}
 
+	memset(node, 0, sizeof(*node));
 	swmod_strncpy(node->line, entry, MAX_LEN_128);
 
 	INIT_LIST_HEAD(&node->list);
-- 
GitLab