Sonarcloud integration

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2023-08-14 01:15:46 +02:00
parent dfd0449306
commit 44adfc0b7d
7 changed files with 68 additions and 11 deletions

45
.github/workflows/sonarcloud.yml vendored Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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)

View File

@@ -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__

View File

@@ -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;

View File

@@ -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-*/**