summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2023-08-14 01:15:46 +0200
committerToni Uhlig <matzeton@googlemail.com>2023-10-05 17:37:42 +0200
commit44adfc0b7d1badd0dd9ed83da3a94477e53203a3 (patch)
tree06b2ab4317b29de4667d9891519b3d703560e788
parentdfd044930689aa6d2af94d15d1372923c5302ffb (diff)
Sonarcloud integration
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--.github/workflows/sonarcloud.yml45
-rw-r--r--README.md6
-rw-r--r--dependencies/nDPIsrvd.h4
-rw-r--r--dependencies/nDPIsrvd.py1
-rw-r--r--examples/c-analysed/c-analysed.c6
-rw-r--r--nDPId-test.c5
-rw-r--r--sonar-project.properites12
7 files changed, 68 insertions, 11 deletions
diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml
new file mode 100644
index 000000000..7ea9dbb63
--- /dev/null
+++ b/.github/workflows/sonarcloud.yml
@@ -0,0 +1,45 @@
+on:
+ push:
+ branches:
+ - main
+ - tmp
+ pull_request:
+ types: [opened, synchronize, reopened]
+
+name: Sonarcloud Scan
+jobs:
+ sonarcloud:
+ runs-on: ubuntu-latest
+ env:
+ BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ fetch-depth: 1
+ - name: Install sonar-scanner and build-wrapper
+ uses: SonarSource/sonarcloud-github-c-cpp@v2
+ - name: Install Prerequisites
+ run: |
+ sudo apt-get update
+ sudo apt-get install autoconf automake cmake libtool pkg-config gettext libjson-c-dev flex bison libpcap-dev zlib1g-dev
+ - name: Run build-wrapper
+ run: |
+ mkdir build
+ cmake -S . -B build -DBUILD_NDPI=ON -DDENABLE_ZLIB=ON -DNDPI_WITH_GCRYPT=OFF
+ build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release
+ - name: Run tests
+ run: |
+ ./test/run_tests.sh ./libnDPI ./build/nDPId-test
+ - name: Run sonar-scanner
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+ run: |
+ sonar-scanner \
+ --define sonar.branch.name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} \
+ --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
+ --define sonar.organization=lnslbrty \
+ --define sonar.projectKey=lnslbrty_nDPId \
+ --define sonar.exclusions=dependencies/uthash/tests/** \
+ --define sonar.verbose=true \
+ --define sonar.python.version=3.8
diff --git a/README.md b/README.md
index 4957e42b9..dbf18023c 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,12 @@
[![Build](https://github.com/utoni/nDPId/actions/workflows/build.yml/badge.svg)](https://github.com/utoni/nDPId/actions/workflows/build.yml)
[![Gitlab-CI](https://gitlab.com/utoni/nDPId/badges/main/pipeline.svg)](https://gitlab.com/utoni/nDPId/-/pipelines)
[![Circle-CI](https://circleci.com/gh/utoni/nDPId.svg?style=shield "Circle-CI")](https://app.circleci.com/pipelines/github/utoni/nDPId)
+[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=lnslbrty_nDPId&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=lnslbrty_nDPId)
+[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=lnslbrty_nDPId&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=lnslbrty_nDPId)
+[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=lnslbrty_nDPId&metric=bugs)](https://sonarcloud.io/summary/new_code?id=lnslbrty_nDPId)
+[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=lnslbrty_nDPId&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=lnslbrty_nDPId)
+[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=lnslbrty_nDPId&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=lnslbrty_nDPId)
+[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=lnslbrty_nDPId&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=lnslbrty_nDPId)
![Docker Automated build](https://img.shields.io/docker/automated/utoni/ndpid)
# References
diff --git a/dependencies/nDPIsrvd.h b/dependencies/nDPIsrvd.h
index 3dcb5d24f..01d9d5c8c 100644
--- a/dependencies/nDPIsrvd.h
+++ b/dependencies/nDPIsrvd.h
@@ -479,7 +479,7 @@ static inline int nDPIsrvd_set_read_timeout(struct nDPIsrvd_socket * const sock,
{
struct timeval tv = {.tv_sec = seconds, .tv_usec = micro_seconds};
- if (sock->fd < 0)
+ if (sock == NULL || sock->fd < 0)
{
return 1;
}
@@ -559,7 +559,7 @@ static inline void nDPIsrvd_cleanup_instance(struct nDPIsrvd_socket * const sock
struct nDPIsrvd_thread_data * current_thread_data;
struct nDPIsrvd_thread_data * ttmp;
- if (instance != NULL)
+ if (sock != NULL && instance != NULL)
{
#ifdef ENABLE_MEMORY_PROFILING
nDPIsrvd_memprof_log("Cleaning up instance 0x%x.", instance->alias_source_key);
diff --git a/dependencies/nDPIsrvd.py b/dependencies/nDPIsrvd.py
index bd15a6bde..5c82d13af 100644
--- a/dependencies/nDPIsrvd.py
+++ b/dependencies/nDPIsrvd.py
@@ -182,7 +182,6 @@ class FlowManager:
if alias not in self.instances:
self.instances[alias] = dict()
if source not in self.instances[alias]:
- self.instances[alias][source] = dict()
self.instances[alias][source] = Instance(alias, source)
self.instances[alias][source].setMostRecentFlowTimeFromJSON(json_dict)
diff --git a/examples/c-analysed/c-analysed.c b/examples/c-analysed/c-analysed.c
index 3f48a01d8..e5f1a4987 100644
--- a/examples/c-analysed/c-analysed.c
+++ b/examples/c-analysed/c-analysed.c
@@ -55,6 +55,12 @@ static void nDPIsrvd_write_flow_info_cb(struct nDPIsrvd_socket const * sock,
(void)instance;
(void)user_data;
+ if (flow == NULL || thread_data == NULL)
+ {
+ fprintf(stderr, "%s\n", "[WriteFlowInfoCallback] BUG: Internal error.");
+ return;
+ }
+
fprintf(stderr,
"[Thread %2d][Flow %5llu][ptr: "
#ifdef __LP64__
diff --git a/nDPId-test.c b/nDPId-test.c
index 19f93be4a..fb21bc65c 100644
--- a/nDPId-test.c
+++ b/nDPId-test.c
@@ -475,6 +475,11 @@ static enum nDPIsrvd_callback_return update_flow_packets_processed(struct nDPIsr
struct nDPIsrvd_json_token const * const flow_total_packets_processed[FD_COUNT] = {
TOKEN_GET_SZ(sock, "flow_src_packets_processed"), TOKEN_GET_SZ(sock, "flow_dst_packets_processed")};
+ if (sock == NULL)
+ {
+ return CALLBACK_ERROR;
+ }
+
if (sock->flow_user_data_size > 0)
{
flow_stats->total_packets_processed = 0;
diff --git a/sonar-project.properites b/sonar-project.properites
index 09631cb2d..82a067f67 100644
--- a/sonar-project.properites
+++ b/sonar-project.properites
@@ -1,12 +1,8 @@
sonar.projectKey=lnslbrty_nDPId
sonar.organization=lnslbrty
-# This is the name and version displayed in the SonarCloud UI.
-#sonar.projectName=nDPId
-#sonar.projectVersion=1.0
+sonar.projectName=nDPId
+sonar.projectVersion=1.5
-# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
-#sonar.sources=.
-
-# Encoding of the source code. Default is default system encoding
-#sonar.sourceEncoding=UTF-8
+sonar.sourceEncoding=UTF-8
+sonar.sources=*.c,*.h,dependencies/nDPIsrvd.h,dependencies/nDPIsrvd.py,examples/c-*/**,examples/cxx-*/**,examples/py-*/**