Unverified Commit 4cbf2698 authored by DL6ER's avatar DL6ER Committed by GitHub
Browse files

Merge pull request #1172 from pi-hole/tweak/static-code-analysis

Improvements based on static-analysis of source code
parents f799b421 ac0346b9
......@@ -711,7 +711,9 @@ void getAllQueries(const char *client_message, const int *sock)
if(command(client_message, ">getallqueries-forward")) {
// Get forward destination name we want to see only (limit length to 255 chars)
forwarddest = calloc(256, sizeof(char));
if(forwarddest == NULL) return;
if(forwarddest == NULL)
return;
sscanf(client_message, ">getallqueries-forward %255s", forwarddest);
filterforwarddest = true;
......@@ -763,7 +765,12 @@ void getAllQueries(const char *client_message, const int *sock)
if(command(client_message, ">getallqueries-domain")) {
// Get domain name we want to see only (limit length to 255 chars)
domainname = calloc(256, sizeof(char));
if(domainname == NULL) return;
if(domainname == NULL)
{
if(forwarddest) free(forwarddest);
return;
}
sscanf(client_message, ">getallqueries-domain %255s", domainname);
filterdomainname = true;
// Iterate through all known domains
......@@ -786,6 +793,7 @@ void getAllQueries(const char *client_message, const int *sock)
// Requested domain has not been found, we directly
// exit here as there is no data to be returned
free(domainname);
if(forwarddest) free(forwarddest);
return;
}
}
......@@ -794,7 +802,13 @@ void getAllQueries(const char *client_message, const int *sock)
if(command(client_message, ">getallqueries-client")) {
// Get client name we want to see only (limit length to 255 chars)
clientname = calloc(256, sizeof(char));
if(clientname == NULL) return;
if(clientname == NULL)
{
if(forwarddest) free(forwarddest);
if(domainname) free(domainname);
return;
}
if(command(client_message, ">getallqueries-client-blocked"))
{
showpermitted = false;
......@@ -834,6 +848,8 @@ void getAllQueries(const char *client_message, const int *sock)
// Requested client has not been found, we directly
// exit here as there is no data to be returned
free(clientname);
if(forwarddest) free(forwarddest);
if(domainname) free(domainname);
return;
}
......@@ -1045,11 +1061,11 @@ void getAllQueries(const char *client_message, const int *sock)
// Use a fixstr because the length of qtype is always 4 (max is 31 for fixstr)
if(!pack_fixstr(*sock, qtype))
return;
break;
// Use str32 for domain and client because we have no idea how long they will be (max is 4294967295 for str32)
if(!pack_str32(*sock, domain) || !pack_str32(*sock, clientIPName))
return;
break;
pack_uint8(*sock, query->status);
pack_uint8(*sock, query->dnssec);
......@@ -1174,8 +1190,7 @@ void getDBstats(const int *sock)
// Get file details
unsigned long long int filesize = get_FTL_db_filesize();
char *prefix = calloc(2, sizeof(char));
if(prefix == NULL) return;
char prefix[2] = { 0 };
double formated = 0.0;
format_memory_size(prefix, filesize, &formated);
......
......@@ -77,7 +77,8 @@ static bool bind_to_telnet_port_IPv4(int *socketdescriptor)
// new instance will fail if there were connections open to the previous
// instance when you killed it. Those connections will hold the TCP port in
// the TIME_WAIT state for 30-120 seconds, so you fall into case 1 above.
setsockopt(*socketdescriptor, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int));
if(setsockopt(*socketdescriptor, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)) != 0)
logg("WARN: allowing re-binding (IPv6) failed: %s", strerror(errno));
struct sockaddr_in serv_addr4;
// set all values in the buffer to zero
......@@ -123,7 +124,8 @@ static bool bind_to_telnet_port_IPv6(int *socketdescriptor)
// stricted to sending and receiving IPv6 packets only. In this
// case, an IPv4 and an IPv6 application can bind to a single port
// at the same time.
setsockopt(*socketdescriptor, IPPROTO_IPV6, IPV6_V6ONLY, &(int){ 1 }, sizeof(int));
if(setsockopt(*socketdescriptor, IPPROTO_IPV6, IPV6_V6ONLY, &(int){ 1 }, sizeof(int)) != 0)
logg("WARN: setting socket to IPv6-only failed: %s", strerror(errno));
// Set SO_REUSEADDR to allow re-binding to the port that has been used
// previously by FTL. A common pattern is that you change FTL's
......@@ -132,7 +134,8 @@ static bool bind_to_telnet_port_IPv6(int *socketdescriptor)
// new instance will fail if there were connections open to the previous
// instance when you killed it. Those connections will hold the TCP port in
// the TIME_WAIT state for 30-120 seconds, so you fall into case 1 above.
setsockopt(*socketdescriptor, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int));
if(setsockopt(*socketdescriptor, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)) != 0)
logg("WARN: allowing re-binding (IPv6) failed: %s", strerror(errno));
struct sockaddr_in6 serv_addr;
// set all values in the buffer to zero
......@@ -341,8 +344,10 @@ static void *telnet_connection_handler_thread(void *socket_desc)
ssize_t n;
while((n = recv(sock,client_message,SOCKETBUFFERLEN-1, 0)))
{
if (n > 0)
if (n > 0 && n < SOCKETBUFFERLEN)
{
// Null-terminate client string
client_message[n] = '\0';
char *message = strdup(client_message);
if(message == NULL) break;
......@@ -419,8 +424,10 @@ static void *socket_connection_handler_thread(void *socket_desc)
ssize_t n;
while((n = recv(sock,client_message,SOCKETBUFFERLEN-1, 0)))
{
if (n > 0)
if (n > 0 && n < SOCKETBUFFERLEN)
{
// Null-terminate client string
client_message[n] = '\0';
char *message = strdup(client_message);
if(message == NULL) break;
......
......@@ -17,9 +17,9 @@
#include "config.h"
#include "log.h"
static const unsigned int capabilityIDs[] = { CAP_CHOWN , CAP_DAC_OVERRIDE , CAP_DAC_READ_SEARCH , CAP_FOWNER , CAP_FSETID , CAP_KILL , CAP_SETGID , CAP_SETUID , CAP_SETPCAP , CAP_LINUX_IMMUTABLE , CAP_NET_BIND_SERVICE , CAP_NET_BROADCAST , CAP_NET_ADMIN , CAP_NET_RAW , CAP_IPC_LOCK , CAP_IPC_OWNER , CAP_SYS_MODULE , CAP_SYS_RAWIO , CAP_SYS_CHROOT , CAP_SYS_PTRACE , CAP_SYS_PACCT , CAP_SYS_ADMIN , CAP_SYS_BOOT , CAP_SYS_NICE , CAP_SYS_RESOURCE , CAP_SYS_TIME , CAP_SYS_TTY_CONFIG , CAP_MKNOD , CAP_LEASE , CAP_AUDIT_WRITE , CAP_AUDIT_CONTROL , CAP_SETFCAP , CAP_MAC_OVERRIDE , CAP_MAC_ADMIN , CAP_SYSLOG , CAP_WAKE_ALARM , CAP_BLOCK_SUSPEND , CAP_AUDIT_READ };
static const char* capabilityNames[] = {"CAP_CHOWN", "CAP_DAC_OVERRIDE", "CAP_DAC_READ_SEARCH", "CAP_FOWNER", "CAP_FSETID", "CAP_KILL", "CAP_SETGID", "CAP_SETUID", "CAP_SETPCAP", "CAP_LINUX_IMMUTABLE", "CAP_NET_BIND_SERVICE", "CAP_NET_BROADCAST", "CAP_NET_ADMIN", "CAP_NET_RAW", "CAP_IPC_LOCK", "CAP_IPC_OWNER", "CAP_SYS_MODULE", "CAP_SYS_RAWIO", "CAP_SYS_CHROOT", "CAP_SYS_PTRACE", "CAP_SYS_PACCT", "CAP_SYS_ADMIN", "CAP_SYS_BOOT", "CAP_SYS_NICE", "CAP_SYS_RESOURCE", "CAP_SYS_TIME", "CAP_SYS_TTY_CONFIG", "CAP_MKNOD", "CAP_LEASE", "CAP_AUDIT_WRITE", "CAP_AUDIT_CONTROL", "CAP_SETFCAP", "CAP_MAC_OVERRIDE", "CAP_MAC_ADMIN", "CAP_SYSLOG", "CAP_WAKE_ALARM", "CAP_BLOCK_SUSPEND", "CAP_AUDIT_READ"};
static const unsigned int numCaps = sizeof(capabilityIDs) / sizeof(const unsigned int);
static const unsigned int capabilityIDs[] = { CAP_CHOWN , CAP_DAC_OVERRIDE , CAP_DAC_READ_SEARCH , CAP_FOWNER , CAP_FSETID , CAP_KILL , CAP_SETGID , CAP_SETUID , CAP_SETPCAP , CAP_LINUX_IMMUTABLE , CAP_NET_BIND_SERVICE , CAP_NET_BROADCAST , CAP_NET_ADMIN , CAP_NET_RAW , CAP_IPC_LOCK , CAP_IPC_OWNER , CAP_SYS_MODULE , CAP_SYS_RAWIO , CAP_SYS_CHROOT , CAP_SYS_PTRACE , CAP_SYS_PACCT , CAP_SYS_ADMIN , CAP_SYS_BOOT , CAP_SYS_NICE , CAP_SYS_RESOURCE , CAP_SYS_TIME , CAP_SYS_TTY_CONFIG , CAP_MKNOD , CAP_LEASE , CAP_AUDIT_WRITE , CAP_AUDIT_CONTROL , CAP_SETFCAP };
static const char* capabilityNames[] = {"CAP_CHOWN", "CAP_DAC_OVERRIDE", "CAP_DAC_READ_SEARCH", "CAP_FOWNER", "CAP_FSETID", "CAP_KILL", "CAP_SETGID", "CAP_SETUID", "CAP_SETPCAP", "CAP_LINUX_IMMUTABLE", "CAP_NET_BIND_SERVICE", "CAP_NET_BROADCAST", "CAP_NET_ADMIN", "CAP_NET_RAW", "CAP_IPC_LOCK", "CAP_IPC_OWNER", "CAP_SYS_MODULE", "CAP_SYS_RAWIO", "CAP_SYS_CHROOT", "CAP_SYS_PTRACE", "CAP_SYS_PACCT", "CAP_SYS_ADMIN", "CAP_SYS_BOOT", "CAP_SYS_NICE", "CAP_SYS_RESOURCE", "CAP_SYS_TIME", "CAP_SYS_TTY_CONFIG", "CAP_MKNOD", "CAP_LEASE", "CAP_AUDIT_WRITE", "CAP_AUDIT_CONTROL", "CAP_SETFCAP"};
static const unsigned int numCaps = sizeof(capabilityIDs) / sizeof(*capabilityIDs);
bool check_capabilities(void)
{
......@@ -59,12 +59,6 @@ bool check_capabilities(void)
for(unsigned int i = 0u; i < numCaps; i++)
{
const unsigned int capid = capabilityIDs[i];
// Check if capability is valid for the current kernel
// If not, exit loop early
if(!cap_valid(capid))
break;
logg("* %-24s (%02u) = %s%s%s *",
capabilityNames[capid], capid,
((data->permitted & (1 << capid)) ? "P":"-"),
......
......@@ -127,7 +127,7 @@ static void removepid(void)
char *getUserName(void)
{
char * name;
char *name;
// the getpwuid() function shall search the user database for an entry with a matching uid
// the geteuid() function shall return the effective user ID of the calling process - this is used as the search criteria for the getpwuid() function
const uid_t euid = geteuid();
......
......@@ -73,7 +73,7 @@ void _dbclose(sqlite3 **db, const char *func, const int line, const char *file)
}
// Always set database pointer to NULL, even when closing failed
*db = NULL;
if(db) *db = NULL;
}
sqlite3* _dbopen(bool create, const char *func, const int line, const char *file)
......@@ -172,16 +172,32 @@ static bool create_counter_table(sqlite3* db)
SQL_bool(db, "CREATE TABLE counters ( id INTEGER PRIMARY KEY NOT NULL, value INTEGER NOT NULL );");
// ID 0 = total queries
db_set_counter(db, DB_TOTALQUERIES, 0);
if(!db_set_counter(db, DB_TOTALQUERIES, 0))
{
logg("create_counter_table(): Failed to set total queries counter to zero!");
return false;
}
// ID 1 = total blocked queries
db_set_counter(db, DB_BLOCKEDQUERIES, 0);
if(!db_set_counter(db, DB_BLOCKEDQUERIES, 0))
{
logg("create_counter_table(): Failed to set blocked queries counter to zero!");
return false;
}
// Time stamp of creation of the counters database
db_set_FTL_property(db, DB_FIRSTCOUNTERTIMESTAMP, (unsigned long)time(0));
if(!db_set_FTL_property(db, DB_FIRSTCOUNTERTIMESTAMP, (unsigned long)time(0)))
{
logg("create_counter_table(): Failed to update first counter timestamp!");
return false;
}
// Update database version to 2
db_set_FTL_property(db, DB_VERSION, 2);
if(!db_set_FTL_property(db, DB_VERSION, 2))
{
logg("create_counter_table(): Failed to update database version!");
return false;
}
return true;
}
......
......@@ -427,6 +427,7 @@ static bool get_client_groupids(clientsData* client)
{
logg("get_client_groupids(%s) - SQL error prepare: %s",
querystr, sqlite3_errstr(rc));
free(hwaddr); // hwaddr != NULL -> memory has been allocated
return false;
}
......@@ -437,6 +438,7 @@ static bool get_client_groupids(clientsData* client)
ip, hwaddr, sqlite3_errstr(rc));
sqlite3_reset(table_stmt);
sqlite3_finalize(table_stmt);
free(hwaddr); // hwaddr != NULL -> memory has been allocated
return false;
}
......@@ -462,6 +464,7 @@ static bool get_client_groupids(clientsData* client)
logg("get_client_groupids(\"%s\", \"%s\") - SQL error step: %s",
ip, hwaddr, sqlite3_errstr(rc));
gravityDB_finalizeTable();
free(hwaddr); // hwaddr != NULL -> memory has been allocated
return false;
}
......@@ -512,6 +515,8 @@ static bool get_client_groupids(clientsData* client)
{
logg("get_client_groupids(%s) - SQL error prepare: %s",
querystr, sqlite3_errstr(rc));
if(hwaddr) free(hwaddr);
free(hostname); // hostname != NULL -> memory has been allocated
return false;
}
......@@ -522,6 +527,8 @@ static bool get_client_groupids(clientsData* client)
ip, hostname, sqlite3_errstr(rc));
sqlite3_reset(table_stmt);
sqlite3_finalize(table_stmt);
if(hwaddr) free(hwaddr);
free(hostname); // hostname != NULL -> memory has been allocated
return false;
}
......@@ -547,6 +554,8 @@ static bool get_client_groupids(clientsData* client)
logg("get_client_groupids(\"%s\", \"%s\") - SQL error step: %s",
ip, hostname, sqlite3_errstr(rc));
gravityDB_finalizeTable();
if(hwaddr) free(hwaddr);
free(hostname); // hostname != NULL -> memory has been allocated
return false;
}
......@@ -598,6 +607,9 @@ static bool get_client_groupids(clientsData* client)
{
logg("get_client_groupids(%s) - SQL error prepare: %s",
querystr, sqlite3_errstr(rc));
if(hwaddr) free(hwaddr);
if(hostname) free(hostname);
free(interface); // interface != NULL -> memory has been allocated
return false;
}
......@@ -608,6 +620,9 @@ static bool get_client_groupids(clientsData* client)
ip, interface, sqlite3_errstr(rc));
sqlite3_reset(table_stmt);
sqlite3_finalize(table_stmt);
if(hwaddr) free(hwaddr);
if(hostname) free(hostname);
free(interface); // interface != NULL -> memory has been allocated
return false;
}
......@@ -633,6 +648,9 @@ static bool get_client_groupids(clientsData* client)
logg("get_client_groupids(\"%s\", \"%s\") - SQL error step: %s",
ip, interface, sqlite3_errstr(rc));
gravityDB_finalizeTable();
if(hwaddr) free(hwaddr);
if(hostname) free(hostname);
free(interface); // interface != NULL -> memory has been allocated
return false;
}
......
......@@ -23,7 +23,7 @@
#include "../signals.h"
// Private prototypes
static char *getMACVendor(const char *hwaddr);
static char *getMACVendor(const char *hwaddr) __attribute__ ((malloc));
enum arp_status { CLIENT_NOT_HANDLED, CLIENT_ARP_COMPLETE, CLIENT_ARP_INCOMPLETE };
bool create_network_table(sqlite3 *db)
......@@ -805,6 +805,9 @@ static bool add_FTL_clients_to_network_table(sqlite3 *db, enum arp_status *clien
if(config.debug & DEBUG_ARP)
logg("Network table: Client %s known through ARP/neigh cache",
ipaddr);
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
unlock_shm();
continue;
}
......@@ -879,6 +882,9 @@ static bool add_FTL_clients_to_network_table(sqlite3 *db, enum arp_status *clien
if(dbID == DB_FAILED)
{
// SQLite error
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
break;
}
// Device not in database, add new entry
......@@ -937,12 +943,22 @@ static bool add_FTL_clients_to_network_table(sqlite3 *db, enum arp_status *clien
unlock_shm();
rc = update_netDB_lastQuery(db, dbID, lastQuery);
if(rc != SQLITE_OK)
{
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
break;
}
// Update number of queries if applicable
rc = update_netDB_numQueries(db, dbID, numQueriesARP);
if(rc != SQLITE_OK)
{
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
break;
}
lock_shm();
// Reacquire client pointer (if may have changed when unlocking above)
......@@ -956,19 +972,34 @@ static bool add_FTL_clients_to_network_table(sqlite3 *db, enum arp_status *clien
// ipaddr is a local copy
rc = add_netDB_network_address(db, dbID, ipaddr);
if(rc != SQLITE_OK)
{
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
break;
}
// Update hostname if available
// hostname is a local copy
rc = update_netDB_name(db, ipaddr, hostname);
if(rc != SQLITE_OK)
{
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
break;
}
// Update interface if available
// interface is a local copy
rc = update_netDB_interface(db, dbID, interface);
if(rc != SQLITE_OK)
{
if(ipaddr) free(ipaddr);
if(hostname) free(hostname);
if(interface) free(interface);
break;
}
// Add to number of processed ARP cache entries
(*additional_entries)++;
......@@ -1116,7 +1147,6 @@ static bool add_local_interfaces_to_network_table(sqlite3 *db, time_t now, unsig
hwaddr, ipaddr, macVendor, iface);
}
// Try to import query data from a possibly previously existing mock-device
int mockID = find_device_by_mock_hwaddr(db, ipaddr);
int lastQuery = 0, firstSeen = now, numQueries = 0;
......@@ -1124,17 +1154,26 @@ static bool add_local_interfaces_to_network_table(sqlite3 *db, time_t now, unsig
{
char *querystr = NULL;
if(asprintf(&querystr, "SELECT lastQuery from network where id = %i", mockID) < 10)
{
free(macVendor);
return false;
}
lastQuery = db_query_int(db, querystr);
free(querystr);
if(asprintf(&querystr, "SELECT firstSeen from network where id = %i", mockID) < 10)
{
free(macVendor);
return false;
}
firstSeen = db_query_int(db, querystr);
free(querystr);
if(asprintf(&querystr, "SELECT numQueries from network where id = %i", mockID) < 10)
{
free(macVendor);
return false;
}
numQueries = db_query_int(db, querystr);
free(querystr);
}
......@@ -1209,7 +1248,7 @@ void parse_neighbor_cache(sqlite3* db)
const char sql[] = "BEGIN TRANSACTION IMMEDIATE";
int rc = dbquery(db, sql);
if( rc != SQLITE_OK )
if(rc != SQLITE_OK)
{
const char *text;
if( rc == SQLITE_BUSY )
......@@ -1219,6 +1258,7 @@ void parse_neighbor_cache(sqlite3* db)
// dbquery() above already logs the reson for why the query failed
logg("%s: Storing devices in network table (\"%s\") failed", text, sql);
pclose(arpfp);
return;
}
......@@ -1229,12 +1269,18 @@ void parse_neighbor_cache(sqlite3* db)
rc = dbquery(db, "DELETE FROM network_addresses "
"WHERE lastSeen < %lu;", (unsigned long)limit);
if(rc != SQLITE_OK)
{
pclose(arpfp);
return;
}
rc = dbquery(db, "UPDATE network_addresses SET name = NULL "
"WHERE nameUpdated < %lu;", (unsigned long)limit);
if(rc != SQLITE_OK)
{
pclose(arpfp);
return;
}
}
// Initialize array of status for individual clients used to
......@@ -1324,15 +1370,15 @@ void parse_neighbor_cache(sqlite3* db)
// findClientID() returned a non-negative index
if(clientID >= 0)
{
client_status[clientID] = CLIENT_ARP_COMPLETE;
clientsData *client = getClient(clientID, true);
if(client != NULL)
{
client_valid = true;
hostname = strdup(getstr(client->namepos));
lastQuery = client->lastQuery;
numQueries = client->numQueriesARP;
}
if(!client)
continue;
client_valid = true;
hostname = strdup(getstr(client->namepos));
lastQuery = client->lastQuery;
numQueries = client->numQueriesARP;
client_status[clientID] = CLIENT_ARP_COMPLETE;
}
else
{
......@@ -1381,7 +1427,12 @@ void parse_neighbor_cache(sqlite3* db)
{
rc = update_netDB_name(db, ip, hostname);
if(rc != SQLITE_OK)
{
// Free allocated memory
free(hostname);
free(macVendor);
break;
}
}
}
else
......@@ -1400,9 +1451,8 @@ void parse_neighbor_cache(sqlite3* db)
// loop interation for the sake of simplicity
}
// Free allocated mememory
// Free allocated memory
free(macVendor);
macVendor = NULL;
}
// Device in database AND client known to Pi-hole
else if(client_valid)
......@@ -1416,13 +1466,20 @@ void parse_neighbor_cache(sqlite3* db)
// Update timestamp of last query if applicable
rc = update_netDB_lastQuery(db, dbID, lastQuery);
if(rc != SQLITE_OK)
{
// Free allocated memory
free(hostname);
break;
}
// Update number of queries if applicable
rc = update_netDB_numQueries(db, dbID, numQueries);
if(rc != SQLITE_OK)
{
// Free allocated memory
free(hostname);
break;
}
lock_shm();
// Acquire client pointer
......@@ -1437,7 +1494,11 @@ void parse_neighbor_cache(sqlite3* db)
// Update hostname if available
rc = update_netDB_name(db, ip, hostname);
if(rc != SQLITE_OK)
{
// Free allocated memory
free(hostname);
break;
}
}
// else: Device in database but not known to Pi-hole
......@@ -1550,7 +1611,8 @@ bool unify_hwaddr(sqlite3 *db)
// Perform SQL query
sqlite3_stmt *stmt = NULL;
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("unify_hwaddr(\"%s\") - SQL error prepare: %s", querystr, sqlite3_errstr(rc));
checkFTLDBrc(rc);
return false;
......@@ -1602,7 +1664,7 @@ bool unify_hwaddr(sqlite3 *db)
return true;
}
static char *getMACVendor(const char *hwaddr)
static char * __attribute__ ((malloc)) getMACVendor(const char *hwaddr)
{
// Special handling for the loopback interface
if(strcmp(hwaddr, "00:00:00:00:00:00") == 0)
......@@ -1626,7 +1688,8 @@ static char *getMACVendor(const char *hwaddr)
sqlite3 *macvendor_db = NULL;
int rc = sqlite3_open_v2(FTLfiles.macvendor_db, &macvendor_db, SQLITE_OPEN_READONLY, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("getMACVendor(\"%s\") - SQL error: %s", hwaddr, sqlite3_errstr(rc));
sqlite3_close(macvendor_db);
return strdup("");
......@@ -1640,7 +1703,8 @@ static char *getMACVendor(const char *hwaddr)
sqlite3_stmt *stmt = NULL;
rc = sqlite3_prepare_v2(macvendor_db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("getMACVendor(\"%s\") - SQL error prepare \"%s\": %s", hwaddr, querystr, sqlite3_errstr(rc));
sqlite3_close(macvendor_db);
return strdup("");
......@@ -1702,7 +1766,8 @@ void updateMACVendorRecords(sqlite3 *db)
sqlite3_stmt *stmt = NULL;
const char *selectstr = "SELECT id,hwaddr FROM network;";
int rc = sqlite3_prepare_v2(db, selectstr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("updateMACVendorRecords() - SQL error prepare \"%s\": %s", selectstr, sqlite3_errstr(rc));
checkFTLDBrc(rc);
return;
......@@ -1730,7 +1795,8 @@ void updateMACVendorRecords(sqlite3 *db)
// Execute prepared statement
char *zErrMsg = NULL;
rc = sqlite3_exec(db, updatestr, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("updateMACVendorRecords() - SQL exec error: \"%s\": %s", updatestr, zErrMsg);
checkFTLDBrc(rc);
sqlite3_free(zErrMsg);
......@@ -1783,7 +1849,8 @@ char *__attribute__((malloc)) getMACfromIP(sqlite3* db, const char *ipaddr)
"(SELECT network_id FROM network_addresses "
"WHERE ip = ? GROUP BY ip HAVING max(lastSeen));";
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("getMACfromIP(\"%s\") - SQL error prepare: %s",
ipaddr, sqlite3_errstr(rc));
checkFTLDBrc(rc);
......@@ -1869,7 +1936,8 @@ int getAliasclientIDfromIP(sqlite3 *db, const char *ipaddr)
"AND aliasclient_id IS NOT NULL "
"GROUP BY ip HAVING max(lastSeen));";
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("getAliasclientIDfromIP(\"%s\") - SQL error prepare: %s",
ipaddr, sqlite3_errstr(rc));
checkFTLDBrc(rc);
......@@ -1951,7 +2019,8 @@ char *__attribute__((malloc)) getNameFromIP(sqlite3 *db, const char *ipaddr)
sqlite3_stmt *stmt = NULL;
const char *querystr = "SELECT name FROM network_addresses WHERE name IS NOT NULL AND ip = ?;";
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("getNameFromIP(\"%s\") - SQL error prepare: %s",
ipaddr, sqlite3_errstr(rc));
checkFTLDBrc(rc);
......@@ -2010,7 +2079,8 @@ char *__attribute__((malloc)) getNameFromIP(sqlite3 *db, const char *ipaddr)
"WHERE ip = ?) "
"ORDER BY lastSeen DESC LIMIT 1";
rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)
{
logg("getNameFromIP(\"%s\") - SQL error prepare: %s",
ipaddr, sqlite3_errstr(rc));
if(db_opened)
......@@ -2093,7 +2163,8 @@ char *__attribute__((malloc)) getIfaceFromIP(sqlite3 *db, const char *ipaddr)
"interface != 'N/A' AND "
"interface IS NOT NULL;";
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
if( rc != SQLITE_OK ){
if(rc != SQLITE_OK)