From 7dbe1a09eb41c97d1cae6ef2351abcbe0ce66e2f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 3 Nov 2021 16:14:31 +0100 Subject: [PATCH] Static analysis improvements Signed-off-by: DL6ER --- src/api/ftl.c | 1 + src/config/toml_reader.c | 4 ++-- src/database/gravity-db.c | 7 ++----- src/dnsmasq_interface.c | 2 +- src/edns0.c | 9 +++++---- src/fifo.c | 2 +- src/shmem.h | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/api/ftl.c b/src/api/ftl.c index 955dd7ad..b56d5c3a 100644 --- a/src/api/ftl.c +++ b/src/api/ftl.c @@ -211,6 +211,7 @@ static int read_temp_sensor(struct ftl_conn *api, cJSON *item = JSON_NEW_OBJ(); if(f_label != NULL && fread(label, sizeof(label)-1, 1, f_label) > 0) { + label[sizeof(label)-1] = '\0'; JSON_OBJ_COPY_STR(item, "name", label); } else diff --git a/src/config/toml_reader.c b/src/config/toml_reader.c index 13bb4d70..7df1eefa 100644 --- a/src/config/toml_reader.c +++ b/src/config/toml_reader.c @@ -117,13 +117,13 @@ bool readFTLtoml(void) toml_table_t *specialDomains = toml_table_in(dns, "specialDomains"); if(specialDomains) { - toml_datum_t mozillaCanary = toml_bool_in(dns, "mozillaCanary"); + toml_datum_t mozillaCanary = toml_bool_in(specialDomains, "mozillaCanary"); if(mozillaCanary.ok) config.special_domains.mozilla_canary = mozillaCanary.u.b; else log_debug(DEBUG_CONFIG, "dns.specialDomains.mozillaCanary DOES NOT EXIST"); - toml_datum_t blockICloudPR = toml_bool_in(dns, "blockICloudPR"); + toml_datum_t blockICloudPR = toml_bool_in(specialDomains, "blockICloudPR"); if(blockICloudPR.ok) config.special_domains.mozilla_canary = blockICloudPR.u.b; else diff --git a/src/database/gravity-db.c b/src/database/gravity-db.c index 1d08a9ac..6386bd19 100644 --- a/src/database/gravity-db.c +++ b/src/database/gravity-db.c @@ -50,7 +50,7 @@ static sqlite3_stmt* auditlist_stmt = NULL; bool gravityDB_opened = false; // Table names corresponding to the enum defined in gravity-db.h -static const char* tablename[] = { "vw_gravity", "vw_blacklist", "vw_whitelist", "vw_regex_blacklist", "vw_regex_whitelist" , "" }; +static const char* tablename[] = { "vw_gravity", "vw_blacklist", "vw_whitelist", "vw_regex_blacklist", "vw_regex_whitelist" , "client", "group", "adlist", "denied_domains", "allowed_domains", "" }; // Prototypes from functions in dnsmasq's source extern void rehash(int size); @@ -900,10 +900,7 @@ static inline void gravityDB_finalize_client_statements(clientsData *client) // Unset group found property to trigger a check next time the // client sends a query - if(client != NULL) - { - client->flags.found_group = false; - } + client->flags.found_group = false; } // Close gravity database connection diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index a90bce00..f124d12e 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -87,7 +87,7 @@ static struct { char name[IFNAMSIZ]; union all_addr addr4; union all_addr addr6; -} next_iface = {false, false, "", {{0}}, {{0}}}; +} next_iface = {false, false, "", {{ 0 }}, {{ 0 }}}; // Fork-private copy of the server data the most recent reply came from static union mysockaddr last_server = {{ 0 }}; diff --git a/src/edns0.c b/src/edns0.c index 1629a85a..0daa31fc 100644 --- a/src/edns0.c +++ b/src/edns0.c @@ -54,14 +54,15 @@ void FTL_parse_pseudoheaders(struct dns_header *header, size_t n, union mysockad // Debug logging if(config.debug & DEBUG_EDNS0) { - char payload[5*plen+1]; + char payload[3*plen+1]; memset(payload, 0, sizeof(payload)); for(unsigned int i = 0; i < plen; i++) - sprintf(&payload[5*i], "0x%02x ", pheader[i]); - log_debug(DEBUG_EDNS0, "EDNS(0) pheader = %s (%lu bytes)", payload, plen); + sprintf(&payload[3*i], "%02X ", pheader[i]); + log_debug(DEBUG_EDNS0, "EDNS(0) pheader: %s (%lu bytes)", + payload, (long unsigned int)plen); } - // Working pointer + // Working pointer unsigned char *p = pheader; // RFC 6891 EDNS(0) Extensions 6.1.2. Wire Format diff --git a/src/fifo.c b/src/fifo.c index d8874247..ee6cff84 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -24,7 +24,7 @@ void add_to_dnsmasq_log_fifo_buffer(const char *payload, const size_t length) { // Log is full, move everything one slot forward to make space for a new record at the end // This pruges the oldest message from the list (it is overwritten by the second message) - memmove(fifo_log->message[0], fifo_log->message[1], (LOG_SIZE - 1u) * MAX_MESSAGE); + memmove(&fifo_log->message[0][0], &fifo_log->message[1][0], (LOG_SIZE - 1u) * MAX_MESSAGE); memmove(&fifo_log->timestamp[0], &fifo_log->timestamp[1], (LOG_SIZE - 1u) * sizeof(fifo_log->timestamp[0])); idx = LOG_SIZE - 1u; } diff --git a/src/shmem.h b/src/shmem.h index d5c7c8f3..a3766fc7 100644 --- a/src/shmem.h +++ b/src/shmem.h @@ -65,7 +65,7 @@ typedef struct { int denied; } domains; } database; - int querytype[TYPE_MAX-1]; + int querytype[TYPE_MAX]; int status[QUERY_STATUS_MAX]; int reply[QUERY_REPLY_MAX]; } countersStruct;