Fixed some SonarCloud issues

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2024-11-13 09:55:40 +01:00
parent 9efdecf4ef
commit 9105b393e1
5 changed files with 28 additions and 21 deletions

View File

@@ -686,7 +686,7 @@ static inline int nDPIsrvd_setup_address(struct nDPIsrvd_address * const address
{ {
address->raw.sa_family = AF_INET; address->raw.sa_family = AF_INET;
address->size = sizeof(address->in); address->size = sizeof(address->in);
address->in.sin_port = htons(atoi(last_colon + 1)); address->in.sin_port = htons((uint16_t)atoi(last_colon + 1));
sock_addr = &address->in.sin_addr; sock_addr = &address->in.sin_addr;
if (len < 7) if (len < 7)
@@ -698,7 +698,7 @@ static inline int nDPIsrvd_setup_address(struct nDPIsrvd_address * const address
{ {
address->raw.sa_family = AF_INET6; address->raw.sa_family = AF_INET6;
address->size = sizeof(address->in6); address->size = sizeof(address->in6);
address->in6.sin6_port = htons(atoi(last_colon + 1)); address->in6.sin6_port = htons((uint16_t)atoi(last_colon + 1));
sock_addr = &address->in6.sin6_addr; sock_addr = &address->in6.sin6_addr;
if (len < 2) if (len < 2)
@@ -803,7 +803,7 @@ static inline enum nDPIsrvd_conversion_return str_value_to_ull(char const * cons
return CONVERSION_OK; return CONVERSION_OK;
} }
static inline nDPIsrvd_hashkey nDPIsrvd_build_key(char const * str, int len) static inline nDPIsrvd_hashkey nDPIsrvd_build_key(char const * str, size_t len)
{ {
uint32_t hash = nDPIsrvd_HASHKEY_SEED; uint32_t hash = nDPIsrvd_HASHKEY_SEED;
uint32_t c; uint32_t c;
@@ -1099,19 +1099,24 @@ static inline struct nDPIsrvd_json_token * nDPIsrvd_find_token(struct nDPIsrvd_s
static inline struct nDPIsrvd_json_token * nDPIsrvd_add_token(struct nDPIsrvd_socket * const sock, static inline struct nDPIsrvd_json_token * nDPIsrvd_add_token(struct nDPIsrvd_socket * const sock,
nDPIsrvd_hashkey hash_value, nDPIsrvd_hashkey hash_value,
int value_token_index) size_t value_token_index)
{ {
struct nDPIsrvd_json_token * token = nDPIsrvd_find_token(sock, hash_value); struct nDPIsrvd_json_token * token = nDPIsrvd_find_token(sock, hash_value);
if (value_token_index >= nDPIsrvd_MAX_JSON_TOKENS)
{
return NULL;
}
if (token != NULL) if (token != NULL)
{ {
token->token_index = value_token_index; token->token_index = (int)value_token_index;
return token; return token;
} }
else else
{ {
struct nDPIsrvd_json_token jt = {.token_keys_hash = hash_value, .token_index = value_token_index, .hh = {}}; struct nDPIsrvd_json_token jt = {.token_keys_hash = hash_value, .token_index = (int)value_token_index, .hh = {}};
utarray_push_back(sock->json.tokens, &jt); utarray_push_back(sock->json.tokens, &jt);
HASH_ADD_INT(sock->json.token_table, HASH_ADD_INT(sock->json.token_table,
@@ -1125,7 +1130,8 @@ static inline struct nDPIsrvd_json_token * nDPIsrvd_add_token(struct nDPIsrvd_so
static inline int nDPIsrvd_walk_tokens( static inline int nDPIsrvd_walk_tokens(
struct nDPIsrvd_socket * const sock, nDPIsrvd_hashkey h, size_t b, int count, uint8_t is_value, uint8_t depth) struct nDPIsrvd_socket * const sock, nDPIsrvd_hashkey h, size_t b, int count, uint8_t is_value, uint8_t depth)
{ {
int i, j; int i;
int j;
jsmntok_t const * key; jsmntok_t const * key;
jsmntok_t const * const t = &sock->jsmn.tokens[b]; jsmntok_t const * const t = &sock->jsmn.tokens[b];
char const * const js = sock->buffer.json_message; char const * const js = sock->buffer.json_message;
@@ -1225,7 +1231,7 @@ static inline struct nDPIsrvd_instance * nDPIsrvd_get_instance(struct nDPIsrvd_s
} }
static inline struct nDPIsrvd_thread_data * nDPIsrvd_get_thread_data( static inline struct nDPIsrvd_thread_data * nDPIsrvd_get_thread_data(
struct nDPIsrvd_socket * const sock, struct nDPIsrvd_socket const * const sock,
struct nDPIsrvd_instance * const instance, struct nDPIsrvd_instance * const instance,
struct nDPIsrvd_json_token const * const thread_id_token, struct nDPIsrvd_json_token const * const thread_id_token,
struct nDPIsrvd_json_token const * const ts_usec_token) struct nDPIsrvd_json_token const * const ts_usec_token)
@@ -1241,7 +1247,7 @@ static inline struct nDPIsrvd_thread_data * nDPIsrvd_get_thread_data(
{ {
nDPIsrvd_ull thread_key; nDPIsrvd_ull thread_key;
TOKEN_VALUE_TO_ULL(sock, thread_id_token, &thread_key); TOKEN_VALUE_TO_ULL(sock, thread_id_token, &thread_key);
thread_id = thread_key; thread_id = (nDPIsrvd_hashkey)thread_key;
} }
HASH_FIND_INT(instance->thread_data_table, &thread_id, thread_data); HASH_FIND_INT(instance->thread_data_table, &thread_id, thread_data);

View File

@@ -83,7 +83,6 @@ class TermColor:
global USE_COLORAMA global USE_COLORAMA
if USE_COLORAMA is True: if USE_COLORAMA is True:
fg_color, bg_color = TermColor.getColorsByHash(string) fg_color, bg_color = TermColor.getColorsByHash(string)
color_hash = TermColor.calcColorHash(string)
return '{}{}{}{}{}'.format(Style.BRIGHT, fg_color, bg_color, string, Style.RESET_ALL) return '{}{}{}{}{}'.format(Style.BRIGHT, fg_color, bg_color, string, Style.RESET_ALL)
else: else:
return '{}{}{}'.format(TermColor.BOLD, string, TermColor.END) return '{}{}{}'.format(TermColor.BOLD, string, TermColor.END)

View File

@@ -594,7 +594,8 @@ static int analysed_map_to_stat(char const * const token_str,
struct global_map const * const map, struct global_map const * const map,
size_t map_length) size_t map_length)
{ {
size_t i, null_i = map_length; size_t i;
size_t null_i = map_length;
for (i = 0; i < map_length; ++i) for (i = 0; i < map_length; ++i)
{ {
@@ -621,7 +622,7 @@ static int analysed_map_to_stat(char const * const token_str,
return 1; return 1;
} }
static int analysed_map_value_to_stat(struct nDPIsrvd_socket * const sock, static int analysed_map_value_to_stat(struct nDPIsrvd_socket const * const sock,
struct nDPIsrvd_json_token const * const token, struct nDPIsrvd_json_token const * const token,
struct global_map const * const map, struct global_map const * const map,
size_t map_length) size_t map_length)
@@ -638,7 +639,7 @@ static int analysed_map_value_to_stat(struct nDPIsrvd_socket * const sock,
return analysed_map_to_stat(value_str, value_length, map, map_length); return analysed_map_to_stat(value_str, value_length, map, map_length);
} }
static void analysed_unmap_flow_from_stat(struct flow_user_data * const flow_user_data) static void analysed_unmap_flow_from_stat(struct flow_user_data const * const flow_user_data)
{ {
if (flow_user_data->is_ip4 != 0) if (flow_user_data->is_ip4 != 0)
{ {
@@ -774,7 +775,7 @@ static ssize_t analysed_map_index(char const * const json_key,
return unknown_key; return unknown_key;
} }
static int analysed_map_flow_u8(struct nDPIsrvd_socket * const sock, static int analysed_map_flow_u8(struct nDPIsrvd_socket const * const sock,
struct nDPIsrvd_json_token const * const token, struct nDPIsrvd_json_token const * const token,
struct global_map const * const map, struct global_map const * const map,
size_t map_length, size_t map_length,
@@ -802,7 +803,7 @@ static int analysed_map_flow_u8(struct nDPIsrvd_socket * const sock,
return 0; return 0;
} }
static void process_flow_stats(struct nDPIsrvd_socket * const sock, struct nDPIsrvd_flow * const flow) static void process_flow_stats(struct nDPIsrvd_socket const * const sock, struct nDPIsrvd_flow * const flow)
{ {
struct flow_user_data * flow_user_data; struct flow_user_data * flow_user_data;
struct nDPIsrvd_json_token const * const flow_event_name = TOKEN_GET_SZ(sock, "flow_event_name"); struct nDPIsrvd_json_token const * const flow_event_name = TOKEN_GET_SZ(sock, "flow_event_name");
@@ -1120,7 +1121,7 @@ static void process_flow_stats(struct nDPIsrvd_socket * const sock, struct nDPIs
} }
} }
static void process_global_stats(struct nDPIsrvd_socket * const sock) static void process_global_stats(struct nDPIsrvd_socket const * const sock)
{ {
struct nDPIsrvd_json_token const * const flow_event = TOKEN_GET_SZ(sock, "flow_event_name"); struct nDPIsrvd_json_token const * const flow_event = TOKEN_GET_SZ(sock, "flow_event_name");
struct nDPIsrvd_json_token const * const packet_event = TOKEN_GET_SZ(sock, "packet_event_name"); struct nDPIsrvd_json_token const * const packet_event = TOKEN_GET_SZ(sock, "packet_event_name");
@@ -1975,7 +1976,8 @@ static int mainloop(int epollfd, struct nDPIsrvd_socket * const sock)
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
int retval = 1, epollfd = -1; int retval = 1;
int epollfd = -1;
init_logging("nDPIsrvd-analysed"); init_logging("nDPIsrvd-analysed");

View File

@@ -197,7 +197,7 @@ static void decode_base64(pcap_dumper_t * const pd,
static void packet_data_copy(void * dst, const void * src) static void packet_data_copy(void * dst, const void * src)
{ {
struct packet_data * const pd_dst = (struct packet_data *)dst; struct packet_data * const pd_dst = (struct packet_data *)dst;
struct packet_data const * const pd_src = (struct packet_data *)src; struct packet_data const * const pd_src = (struct packet_data const *)src;
*pd_dst = *pd_src; *pd_dst = *pd_src;
if (pd_src->base64_packet != NULL && pd_src->base64_packet_size > 0) if (pd_src->base64_packet != NULL && pd_src->base64_packet_size > 0)
{ {
@@ -224,7 +224,7 @@ static void packet_data_dtor(void * elt)
static void flow_packet_data_copy(void * dst, const void * src) static void flow_packet_data_copy(void * dst, const void * src)
{ {
struct flow_packet_data * const pd_dst = (struct flow_packet_data *)dst; struct flow_packet_data * const pd_dst = (struct flow_packet_data *)dst;
struct flow_packet_data const * const pd_src = (struct flow_packet_data *)src; struct flow_packet_data const * const pd_src = (struct flow_packet_data const *)src;
*pd_dst = *pd_src; *pd_dst = *pd_src;
if (pd_src->base64_packet != NULL && pd_src->base64_packet_size > 0) if (pd_src->base64_packet != NULL && pd_src->base64_packet_size > 0)
{ {
@@ -1175,7 +1175,7 @@ static int parse_options(int argc, char ** argv)
break; break;
case 'R': case 'R':
{ {
char * value = (optarg[0] == '~' ? optarg + 1 : optarg); char const * const value = (optarg[0] == '~' ? optarg + 1 : optarg);
nDPIsrvd_ull risk; nDPIsrvd_ull risk;
if (perror_ull(str_value_to_ull(value, &risk), "process_risky") != CONVERSION_OK) if (perror_ull(str_value_to_ull(value, &risk), "process_risky") != CONVERSION_OK)
{ {

View File

@@ -1359,7 +1359,7 @@ static void usage(char const * const arg0)
fprintf(stderr, "usage: %s [path-to-pcap-file] [optional-nDPId-config-file]\n", arg0); fprintf(stderr, "usage: %s [path-to-pcap-file] [optional-nDPId-config-file]\n", arg0);
} }
static int thread_wait_for_termination(pthread_t thread, time_t wait_time_secs, struct thread_return_value * const trv) static int thread_wait_for_termination(pthread_t thread, time_t wait_time_secs, struct thread_return_value * trv)
{ {
#if !defined(__FreeBSD__) && !defined(__APPLE__) #if !defined(__FreeBSD__) && !defined(__APPLE__)
struct timespec ts; struct timespec ts;