summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2023-11-06 23:49:51 +0100
committerToni Uhlig <matzeton@googlemail.com>2023-11-07 00:02:36 +0100
commit5d56288a113aa3aa2e68dbf54f0acde0650bafcb (patch)
treebc4e9904feac2a8c9e5f5287774416b1aa3822f9
parent84b12cd02c1f11d134f00b0a066414a677a53719 (diff)
Fixed more SonarCloud complaints.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--Dockerfile13
-rw-r--r--dependencies/nDPIsrvd.py2
-rw-r--r--examples/c-captured/c-captured.c7
-rw-r--r--examples/c-notifyd/c-notifyd.c2
-rwxr-xr-xexamples/py-machine-learning/keras-autoencoder.py3
-rw-r--r--nDPId-test.c4
-rw-r--r--nDPId.c26
-rw-r--r--nDPIsrvd.c4
-rw-r--r--nio.c2
-rw-r--r--nio.h2
10 files changed, 33 insertions, 32 deletions
diff --git a/Dockerfile b/Dockerfile
index 651cbee08..d5f42a670 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,12 +1,11 @@
FROM ubuntu:22.04 AS builder
WORKDIR /root
-
-RUN env DEBIAN_FRONTEND=noninteractive apt-get -y update && apt-get install -y --no-install-recommends autoconf automake build-essential ca-certificates wget unzip git make cmake pkg-config libpcap-dev autoconf libtool
-RUN env DEBIAN_FRONTEND=noninteractive apt-get clean
-RUN env DEBIAN_FRONTEND=noninteractive apt-get autoclean
+RUN apt-get -y update && apt-get install -y --no-install-recommends autoconf automake build-essential ca-certificates wget unzip git make cmake pkg-config libpcap-dev autoconf libtool && apt-get clean
RUN git clone https://github.com/utoni/nDPId.git
-RUN cd nDPId && mkdir -p build && cd build && cmake .. -DBUILD_NDPI=ON && make
+
+WORKDIR /root/nDPId
+RUN cmake -S . -B build -DBUILD_NDPI=ON && cmake --build build --verbose
FROM ubuntu:22.04
USER root
@@ -15,9 +14,7 @@ WORKDIR /
COPY --from=builder /root/nDPId/build/nDPId /usr/sbin/nDPId
COPY --from=builder /root/nDPId/build/nDPIsrvd /usr/bin/nDPIsrvd
-RUN env DEBIAN_FRONTEND=noninteractive apt-get -y update && apt-get install -y --no-install-recommends libpcap-dev
-RUN env DEBIAN_FRONTEND=noninteractive apt-get clean
-RUN env DEBIAN_FRONTEND=noninteractive apt-get autoclean
+RUN apt-get -y update && apt-get install -y --no-install-recommends libpcap-dev && apt-get clean
USER nobody
RUN /usr/bin/nDPIsrvd -h || { RC=$?; test ${RC} -eq 1; }
diff --git a/dependencies/nDPIsrvd.py b/dependencies/nDPIsrvd.py
index 5c82d13af..8e14aa47d 100644
--- a/dependencies/nDPIsrvd.py
+++ b/dependencies/nDPIsrvd.py
@@ -369,7 +369,7 @@ class nDPIsrvdSocket:
sys.stderr.write('Error while evaluating expression "{}"\n'.format(jf.filter_string))
raise err
- if type(json_filter_retval) != bool:
+ if not isinstance(json_filter_retval, bool):
print()
sys.stderr.write('Error while evaluating expression "{}"\n'.format(jf.filter_string))
raise nDPIsrvdException('JSON Filter returned an invalid type: expected bool, got {}'.format(type(json_filter_retval)))
diff --git a/examples/c-captured/c-captured.c b/examples/c-captured/c-captured.c
index e810f3e70..14457a175 100644
--- a/examples/c-captured/c-captured.c
+++ b/examples/c-captured/c-captured.c
@@ -666,7 +666,8 @@ static void syslog_event(struct nDPIsrvd_socket * const sock,
}
if (src_port != NULL && dst_port != NULL)
{
- size_t src_port_len = 0, dst_port_len = 0;
+ size_t src_port_len = 0;
+ size_t dst_port_len = 0;
char const * const tmp_src_port_str = TOKEN_GET_VALUE(sock, src_port, &src_port_len);
char const * const tmp_dst_port_str = TOKEN_GET_VALUE(sock, dst_port, &dst_port_len);
if (tmp_src_port_str != NULL && tmp_dst_port_str != NULL)
@@ -938,8 +939,8 @@ static enum nDPIsrvd_callback_return captured_json_callback(struct nDPIsrvd_sock
syslog_event(sock, flow, "midstream");
}
- if ((flow_user->packets == NULL || flow_user->flow_max_packets == 0 ||
- utarray_len(flow_user->packets) == 0))
+ if (flow_user->packets == NULL || flow_user->flow_max_packets == 0 ||
+ utarray_len(flow_user->packets) == 0)
{
if (logging_mode != 0)
{
diff --git a/examples/c-notifyd/c-notifyd.c b/examples/c-notifyd/c-notifyd.c
index 837f59ff6..0c9b52f3e 100644
--- a/examples/c-notifyd/c-notifyd.c
+++ b/examples/c-notifyd/c-notifyd.c
@@ -21,7 +21,7 @@ enum dbus_level
static char const * const flow_severities[] = {"Low", "Medium", "High", "Severe", "Critical", "Emergency"};
static char const * const flow_breeds[] = {
- "Safe", "Acceptable", "Fun", "Unsafe", "Potentially Dangerous", "Tracker/Ads", "Dangerous", "Unrated", "???"};
+ "Safe", "Acceptable", "Fun", "Unsafe", "Potentially Dangerous", "Tracker\\/Ads", "Dangerous", "Unrated", "???"};
static char const * const flow_categories[] = {"Unspecified",
"Media",
"VPN",
diff --git a/examples/py-machine-learning/keras-autoencoder.py b/examples/py-machine-learning/keras-autoencoder.py
index 086cf505c..fc3115012 100755
--- a/examples/py-machine-learning/keras-autoencoder.py
+++ b/examples/py-machine-learning/keras-autoencoder.py
@@ -273,8 +273,7 @@ def plot_worker(shared_shutdown_event, shared_plot_queue):
ys2 = []
ys3 = []
ys4 = []
- x = 0
- a = ani.FuncAnimation(fig, plot_animate, fargs=(shared_plot_queue, (ax1, ax2, ax3, ax4), xs, (ys1, ys2, ys3, ys4)), interval=1000, cache_frame_data=False)
+ ani.FuncAnimation(fig, plot_animate, fargs=(shared_plot_queue, (ax1, ax2, ax3, ax4), xs, (ys1, ys2, ys3, ys4)), interval=1000, cache_frame_data=False)
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
plt.margins(x=0, y=0)
plt.show()
diff --git a/nDPId-test.c b/nDPId-test.c
index 3d12a6013..8f69350f9 100644
--- a/nDPId-test.c
+++ b/nDPId-test.c
@@ -627,9 +627,9 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s
goto callback_error;
}
- nDPIsrvd_ull pkt_id = 0ull;
+ nDPIsrvd_ull pkt_id = 0ULL;
TOKEN_VALUE_TO_ULL(sock, packet_id, &pkt_id);
- if (pkt_id == 0ull)
+ if (pkt_id == 0ULL)
{
logger(1, "%s", "Missing packet id");
goto callback_error;
diff --git a/nDPId.c b/nDPId.c
index 7865b5298..74216da4d 100644
--- a/nDPId.c
+++ b/nDPId.c
@@ -1560,8 +1560,12 @@ static int setup_reader_threads(void)
"Could not get netmask for pcap device %s: %s",
get_cmdarg(&nDPId_options.pcap_file_or_interface),
strerror(errno));
- } else {
- logger_early(1, "Unexpected error while retrieving netmask for pcap device %s", get_cmdarg(&nDPId_options.pcap_file_or_interface));
+ }
+ else
+ {
+ logger_early(1,
+ "Unexpected error while retrieving netmask for pcap device %s",
+ get_cmdarg(&nDPId_options.pcap_file_or_interface));
}
return 1;
}
@@ -2661,15 +2665,13 @@ static void jsonize_packet_event(struct nDPId_reader_thread * const reader_threa
reader_thread->workflow->packets_captured,
reader_thread->array_index);
}
- else if (base64_data_len > 0)
+ else if (base64_data_len > 0 &&
+ ndpi_serialize_string_binary(&workflow->ndpi_serializer, "pkt", base64_data, (uint16_t)base64_data_len) != 0)
{
- if (ndpi_serialize_string_binary(&workflow->ndpi_serializer, "pkt", base64_data, base64_data_len) != 0)
- {
- logger(1,
- "[%8llu, %zu] JSON serializing base64 packet buffer failed",
- reader_thread->workflow->packets_captured,
- reader_thread->array_index);
- }
+ logger(1,
+ "[%8llu, %zu] JSON serializing base64 packet buffer failed",
+ reader_thread->workflow->packets_captured,
+ reader_thread->array_index);
}
serialize_and_send(reader_thread);
}
@@ -4391,8 +4393,8 @@ static void run_pcap_loop(struct nDPId_reader_thread * const reader_thread)
struct nio io;
nio_init(&io);
#ifdef ENABLE_EPOLL
- if ((nDPId_options.use_poll == 0 && nio_use_epoll(&io, 32) != NIO_SUCCESS)
- || (nDPId_options.use_poll != 0 && nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS))
+ if ((nDPId_options.use_poll == 0 && nio_use_epoll(&io, 32) != NIO_SUCCESS) ||
+ (nDPId_options.use_poll != 0 && nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS))
#else
if (nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS)
#endif
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index 37034751f..cb4c08a45 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -384,6 +384,7 @@ static int drain_write_buffers(struct remote_desc * const remote)
while ((written = write(remote->fd, buf->buf.ptr.raw + buf->written, buf->buf.used - buf->written)) < 0 &&
errno == EINTR)
{
+ // Retry if interrupted by a signal.
}
switch (written)
{
@@ -447,7 +448,7 @@ static int handle_outgoing_data(struct nio * const io, struct remote_desc * cons
}
if (utarray_len(additional_write_buffers) == 0)
{
- struct nDPIsrvd_write_buffer * const write_buffer = get_write_buffer(remote);
+ struct nDPIsrvd_write_buffer const * const write_buffer = get_write_buffer(remote);
if (write_buffer->buf.used == 0)
{
@@ -1261,6 +1262,7 @@ static int handle_incoming_data(struct nio * const io, struct remote_desc * cons
json_read_buffer->buf.max - json_read_buffer->buf.used)) < 0 &&
errno == EINTR)
{
+ // Retry if interrupted by a signal.
}
if (bytes_read < 0 || errno != 0)
{
diff --git a/nio.c b/nio.c
index babccb75e..90785eeaa 100644
--- a/nio.c
+++ b/nio.c
@@ -329,7 +329,7 @@ int nio_check(struct nio * io, int index, int event_flags)
return NIO_ERROR_INTERNAL;
}
-int nio_is_valid(struct nio * io, int index)
+int nio_is_valid(struct nio const * const io, int index)
{
if (index < 0 || index >= io->nready)
return NIO_ERROR_INTERNAL;
diff --git a/nio.h b/nio.h
index a0ac0b6b0..76bb7c8cb 100644
--- a/nio.h
+++ b/nio.h
@@ -53,7 +53,7 @@ static inline int nio_get_nready(struct nio const * const io)
int nio_check(struct nio * io, int index, int events);
-int nio_is_valid(struct nio * io, int index);
+int nio_is_valid(struct nio const * const io, int index);
int nio_get_fd(struct nio * io, int index);