Merge branch 'development' into new/query_special_domain

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2022-04-24 09:26:46 +02:00
46 changed files with 210 additions and 129 deletions
+4
View File
@@ -0,0 +1,4 @@
ede
edn
nd
tre
+19
View File
@@ -0,0 +1,19 @@
name: Codespell
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
spell-check:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
-
name: Checkout repository
uses: actions/checkout@v3
-
name: Spell-Checking
uses: codespell-project/actions-codespell@master
with:
ignore_words_file: .codespellignore
skip: ./src/database/sqlite3.c,./src/database/sqlite3.h,./src/database/shell.c,./src/lua,./src/dnsmasq,./src/tre-regex
+2 -1
View File
@@ -147,7 +147,8 @@ set(sources
shmem.h
signals.c
signals.h
static_assert.h
struct_size.c
struct_size.h
timers.c
timers.h
vector.c
+1 -1
View File
@@ -111,7 +111,7 @@
#define NUM_RECHECKS 3
// Use out own syscalls handling functions that will detect possible errors
// and report accordingly in the log. This will make debugging FTL crashs
// and report accordingly in the log. This will make debugging FTL crash
// caused by insufficient memory or by code bugs (not properly dealing
// with NULL pointers) much easier.
#undef strdup // strdup() is a macro in itself, it needs special handling
+8 -8
View File
@@ -46,7 +46,7 @@ extern char *querystr(char *desc, unsigned short type);
#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
/* qsort comparision function (count field), sort ASC */
/* qsort comparison function (count field), sort ASC */
static int __attribute__((pure)) cmpasc(const void *a, const void *b)
{
const int *elem1 = (int*)a;
@@ -551,7 +551,7 @@ void getUpstreamDestinations(const char *client_message, const int *sock)
name = ip;
if(totalqueries > 0)
// Whats the percentage of blocked queries on the total amount of queries?
// What's the percentage of blocked queries on the total amount of queries?
percentage = 1e2f * blocked / totalqueries;
}
else if(i == -2)
@@ -561,7 +561,7 @@ void getUpstreamDestinations(const char *client_message, const int *sock)
name = ip;
if(totalqueries > 0)
// Whats the percentage of cached queries on the total amount of queries?
// What's the percentage of cached queries on the total amount of queries?
percentage = 1e2f * cached / totalqueries;
}
else if(i == -1)
@@ -571,7 +571,7 @@ void getUpstreamDestinations(const char *client_message, const int *sock)
name = ip;
if(totalqueries > 0)
// Whats the percentage of cached queries on the total amount of queries?
// What's the percentage of cached queries on the total amount of queries?
percentage = 1e2f * others / totalqueries;
}
else
@@ -1165,7 +1165,7 @@ void getRecentBlocked(const char *client_message, const int *sock)
else if(!pack_str32(*sock, domain))
return;
// Only count when sent succesfully
// Only count when sent successfully
found++;
}
@@ -1238,12 +1238,12 @@ void getDBstats(const int *sock)
unsigned long long int filesize = get_FTL_db_filesize();
char prefix[2] = { 0 };
double formated = 0.0;
format_memory_size(prefix, filesize, &formated);
double formatted = 0.0;
format_memory_size(prefix, filesize, &formatted);
if(istelnet[*sock])
ssend(*sock, "queries in database: %i\ndatabase filesize: %.2f %sB\nSQLite version: %s\n",
get_number_of_queries_in_DB(NULL), formated, prefix, get_sqlite3_version());
get_number_of_queries_in_DB(NULL), formatted, prefix, get_sqlite3_version());
else {
pack_int32(*sock, get_number_of_queries_in_DB(NULL));
pack_int64(*sock, filesize);
+6
View File
@@ -354,6 +354,12 @@ void parse_args(int argc, char* argv[])
exit(EXIT_SUCCESS);
}
// Return number of errors on this undocumented flag
if(strcmp(argv[i], "--check-structs") == 0)
{
exit(check_struct_sizes());
}
// Complain if invalid options have been found
if(!ok)
{
+3
View File
@@ -24,4 +24,7 @@ const char *cli_done(void) __attribute__ ((const));
const char *cli_bold(void) __attribute__ ((const));
const char *cli_normal(void) __attribute__ ((const));
// defined in dnsmasq_interface.c
int check_struct_sizes(void);
#endif //ARGS_H
+4 -3
View File
@@ -17,10 +17,12 @@
#include <sys/types.h>
// typedef uni32_t
#include <stdint.h>
// assert_sizeof
#include "static_assert.h"
// struct in_addr, in6_addr
#include <netinet/in.h>
// type bool
#include <stdbool.h>
// type FILE
#include <stdio.h>
void init_config_mutex(void);
void getLogFilePath(void);
@@ -91,7 +93,6 @@ typedef struct {
} ip_blocking;
} reply_addr;
} ConfigStruct;
ASSERT_SIZEOF(ConfigStruct, 112, 104, 104);
typedef struct {
const char* conf;
+1 -1
View File
@@ -214,7 +214,7 @@ static void terminate_threads(void)
if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
{
logg("Thread %s (%d) is busy, cancelling it (cannot set timout).",
logg("Thread %s (%d) is busy, cancelling it (cannot set timeout).",
thread_names[i], i);
pthread_cancel(threads[i]);
continue;
+2 -2
View File
@@ -659,7 +659,7 @@ static bool get_client_groupids(clientsData* client)
}
// We use the default group and return early here
// if aboves lookups didn't return any results
// if above lookups didn't return any results
// (the client is not configured through the client table)
if(chosen_match_id < 0)
{
@@ -1160,7 +1160,7 @@ static enum db_result domain_in_list(const char *domain, sqlite3_stmt *stmt, con
// Bind domain to prepared statement
// SQLITE_STATIC: Use the string without first duplicating it internally.
// We can do this as domain has dynamic scope that exceeds that of the binding.
// We need to bind the domain onl once even to the prepared audit statement as:
// We need to bind the domain only once even to the prepared audit statement as:
// When the same named SQL parameter is used more than once, second and
// subsequent occurrences have the same index as the first occurrence.
// (https://www.sqlite.org/c3ref/bind_blob.html)
+3 -3
View File
@@ -1256,7 +1256,7 @@ void parse_neighbor_cache(sqlite3* db)
else
text = "ERROR";
// dbquery() above already logs the reson for why the query failed
// dbquery() above already logs the reason for why the query failed
logg("%s: Storing devices in network table (\"%s\") failed", text, sql);
pclose(arpfp);
return;
@@ -1448,7 +1448,7 @@ void parse_neighbor_cache(sqlite3* db)
unmock_netDB_device(db, hwaddr, macVendor, dbID);
// Host name, count and last query timestamp will be set in the next
// loop interation for the sake of simplicity
// loop iteration for the sake of simplicity
}
// Free allocated memory
@@ -1545,7 +1545,7 @@ void parse_neighbor_cache(sqlite3* db)
// Finally, loop over the available interfaces to ensure we list the
// IP addresses correctly (local addresses are NOT contained in the
// ARP/neighor cache).
// ARP/neighbor cache).
if(!add_local_interfaces_to_network_table(db, now, &additional_entries))
return;
+2 -2
View File
@@ -486,7 +486,7 @@ int DB_save_queries(sqlite3 *db)
return DB_FAILED;
}
// Store index for next loop interation round and update last time stamp
// Store index for next loop iteration round and update last time stamp
// in the database only if all queries have been saved successfully
if(saved > 0 && !error)
{
@@ -935,7 +935,7 @@ void DB_read_queries(void)
}
else if(status == QUERY_REGEX)
{
// QUERY_REGEX: Set ID regex which was the reson for blocking
// QUERY_REGEX: Set ID regex which was the reason for blocking
const int cacheID = findCacheID(query->domainID, query->clientID, query->type);
DNSCacheData *cache = getDNSCache(cacheID, true);
// Only load if
+1 -1
View File
@@ -302,7 +302,7 @@ void change_clientcount(clientsData *client, int total, int blocked, int overTim
if(overTimeIdx > -1 && overTimeIdx < OVERTIME_SLOTS)
client->overTime[overTimeIdx] += overTimeMod;
// Also add counts to the conencted alias-client (if any)
// Also add counts to the connected alias-client (if any)
if(client->flags.aliasclient)
{
logg("WARN: Should not add to alias-client directly (client \"%s\" (%s))!",
+3 -9
View File
@@ -15,8 +15,9 @@
// enum privacy_level
#include "enums.h"
// assert_sizeof
#include "static_assert.h"
// Definitions like OVERTIME_SLOT
#include "FTL.h"
extern const char *querytypes[TYPE_MAX];
@@ -51,9 +52,6 @@ typedef struct {
} flags;
} queriesData;
// ARM needs extra padding at the end
ASSERT_SIZEOF(queriesData, 56, 44, 44);
typedef struct {
unsigned char magic;
bool new;
@@ -64,7 +62,6 @@ typedef struct {
size_t namepos;
time_t lastQuery;
} upstreamsData;
ASSERT_SIZEOF(upstreamsData, 640, 624, 624);
typedef struct {
unsigned char magic;
@@ -91,7 +88,6 @@ typedef struct {
time_t lastQuery;
time_t firstSeen;
} clientsData;
ASSERT_SIZEOF(clientsData, 696, 668, 668);
typedef struct {
unsigned char magic;
@@ -100,7 +96,6 @@ typedef struct {
uint32_t domainhash;
size_t domainpos;
} domainsData;
ASSERT_SIZEOF(domainsData, 24, 20, 20);
typedef struct {
unsigned char magic;
@@ -111,7 +106,6 @@ typedef struct {
int clientID;
int black_regex_idx;
} DNSCacheData;
ASSERT_SIZEOF(DNSCacheData, 16, 16, 16);
void strtolower(char *str);
uint32_t hashStr(const char *s) __attribute__((const));
+1 -1
View File
@@ -438,7 +438,7 @@ static void print_dhcp_offer(struct in_addr source, dhcp_packet_data *offer_pack
unsigned int n = 0;
for(unsigned int i = 1; n < optlen; i++)
{
// Extract destionation descriptor
// Extract destination descriptor
unsigned char cidr = offer_packet->options[x+n++];
unsigned char addr[4] = { 0 };
if(cidr > 0)
+34 -5
View File
@@ -48,6 +48,10 @@
#include "api/api_helper.h"
// logg_rate_limit_message()
#include "database/message-table.h"
// type struct sqlite3_stmt_vec
#include "vector.h"
// check_one_struct()
#include "struct_size.h"
// Private prototypes
static void print_flags(const unsigned int flags);
@@ -841,7 +845,7 @@ void _FTL_iface(struct irec *recviface, const union all_addr *addr, const sa_fam
next_iface.name[0] = '-';
next_iface.name[1] = '\0';
// Check if we need to identify the receving interface by its address
// Check if we need to identify the receiving interface by its address
if(!recviface && addr &&
((addrfamily == AF_INET && addr->addr4.s_addr != INADDR_ANY) ||
(addrfamily == AF_INET6 && !IN6_IS_ADDR_UNSPECIFIED(&addr->addr6))))
@@ -1723,7 +1727,7 @@ static void FTL_forwarded(const unsigned int flags, const char *name, const unio
// up in a situation where dnsmasq can answer the first level of
// the DNS result (the CNAME) from cache, hence the status of this
// query is marked as "answered from cache" in FTLDNS. However, for
// server.a.com wit the much shorter TTL, we still have to forward
// server.a.com with the much shorter TTL, we still have to forward
// something and ask the upstream server for the final IP address.
// Correct reply timer if a response time has already been calculated
@@ -1948,7 +1952,7 @@ static void FTL_reply(const unsigned int flags, const char *name, const union al
}
else if(rcode == SERVFAIL)
{
// This happens on upstream destionation errors
// This happens on upstream destination errors
answer = "SERVFAIL";
}
}
@@ -2071,7 +2075,7 @@ static void FTL_reply(const unsigned int flags, const char *name, const union al
// Answered from local configuration, might be a wildcard or user-provided
// Answered from a custom (user provided) cache file or because
// we're the authorative DNS server (e.g. DHCP server and this
// we're the authoritative DNS server (e.g. DHCP server and this
// is our own domain)
query_set_status(query, QUERY_CACHE);
@@ -2771,7 +2775,7 @@ void FTL_fork_and_bind_sockets(struct passwd *ent_pw)
// Add our PTR record to the end of the linked list
if(daemon->ptr != NULL)
{
// Interate to the last PTR entry in dnsmasq's structure
// Iterate to the last PTR entry in dnsmasq's structure
struct ptr_record *ptr;
for(ptr = daemon->ptr; ptr && ptr->next; ptr = ptr->next);
@@ -3335,3 +3339,28 @@ static void _query_set_dnssec(queriesData *query, const enum dnssec_status dnsse
// Set DNSSEC status
query->dnssec = dnssec;
}
// Check sizes of all important in-memory objects. This routine returns the number of
// errors found (i.e., a return value of 0 is what we want and expect)
int check_struct_sizes(void)
{
int result = 0;
result += check_one_struct("ConfigStruct", sizeof(ConfigStruct), 112, 104);
result += check_one_struct("queriesData", sizeof(queriesData), 56, 44);
result += check_one_struct("upstreamsData", sizeof(upstreamsData), 640, 624);
result += check_one_struct("clientsData", sizeof(clientsData), 696, 668);
result += check_one_struct("domainsData", sizeof(domainsData), 24, 20);
result += check_one_struct("DNSCacheData", sizeof(DNSCacheData), 16, 16);
result += check_one_struct("ednsData", sizeof(ednsData), 72, 72);
result += check_one_struct("overTimeData", sizeof(overTimeData), 32, 24);
result += check_one_struct("regexData", sizeof(regexData), 56, 44);
result += check_one_struct("SharedMemory", sizeof(SharedMemory), 24, 12);
result += check_one_struct("ShmSettings", sizeof(ShmSettings), 12, 12);
result += check_one_struct("countersStruct", sizeof(countersStruct), 244, 244);
result += check_one_struct("sqlite3_stmt_vec", sizeof(sqlite3_stmt_vec), 32, 16);
if(result == 0)
printf("All okay\n");
return result;
}
-4
View File
@@ -10,9 +10,6 @@
#ifndef EDNS0_HEADER
#define EDNS0_HEADER
// assert_sizeof
#include "static_assert.h"
typedef struct {
bool client_set;
bool mac_set;
@@ -20,7 +17,6 @@ typedef struct {
char mac_byte[6];
char mac_text[18];
} ednsData;
ASSERT_SIZEOF(ednsData, 72, 72, 72);
void FTL_parse_pseudoheaders(struct dns_header *header, size_t n, union mysockaddr *peer, ednsData *edns);
+1 -1
View File
@@ -26,7 +26,7 @@ static const char *eventtext(const enum events event);
static volatile atomic_flag eventqueue[EVENTS_MAX] = { ATOMIC_FLAG_INIT };
// Set/Request event
// We set the events atomically to ensure no race collisons can happen. If an
// We set the events atomically to ensure no race collisions can happen. If an
// event has already been requested, this has no consequences as event cannot be
// added multiple times
void _set_event(const enum events event, int line, const char *function, const char *file)
+8 -8
View File
@@ -138,11 +138,11 @@ void ls_dir(const char* path)
st.st_mode & S_IXOTH ? "x":"-");
char prefix[2] = { 0 };
double formated = 0.0;
format_memory_size(prefix, (unsigned long long)st.st_size, &formated);
double formatted = 0.0;
format_memory_size(prefix, (unsigned long long)st.st_size, &formatted);
// Log output for this file
logg("%s %-15s %3.0f%s %s", permissions, usergroup, formated, prefix, filename);
logg("%s %-15s %3.0f%s %s", permissions, usergroup, formatted, prefix, filename);
}
logg("---------------------------------------------------");
@@ -171,17 +171,17 @@ int get_path_usage(const char *path, char buffer[64])
// Create human-readable total size
char prefix_size[2] = { 0 };
double formated_size = 0.0;
format_memory_size(prefix_size, size, &formated_size);
double formatted_size = 0.0;
format_memory_size(prefix_size, size, &formatted_size);
// Generate human-readable "total used" size
char prefix_used[2] = { 0 };
double formated_used = 0.0;
format_memory_size(prefix_used, used, &formated_used);
double formatted_used = 0.0;
format_memory_size(prefix_used, used, &formatted_used);
// Print result into buffer passed to this subroutine
snprintf(buffer, 64, "%s: %.1f%sB used, %.1f%sB total", path,
formated_used, prefix_used, formated_size, prefix_size);
formatted_used, prefix_used, formatted_size, prefix_size);
// Return percentage of used shared memory
// Adding 1 avoids FPE if the size turns out to be zero
+6 -6
View File
@@ -96,7 +96,7 @@ void _FTL_log(const bool newline, const bool debug, const char *format, ...)
char idstr[42];
const int pid = getpid(); // Get the process ID of the calling process
const int mpid = main_pid(); // Get the process ID of the main FTL process
const int tid = gettid(); // Get the thread ID of the callig process
const int tid = gettid(); // Get the thread ID of the calling process
// There are four cases we have to differentiate here:
if(pid == tid)
@@ -197,16 +197,16 @@ void FTL_log_helper(const unsigned char n, ...)
}
void format_memory_size(char prefix[2], const unsigned long long int bytes,
double * const formated)
double * const formatted)
{
unsigned int i;
*formated = bytes;
*formatted = bytes;
// Determine exponent for human-readable display
for(i = 0; i < 7; i++)
{
if(*formated <= 1e3)
if(*formatted <= 1e3)
break;
*formated /= 1e3;
*formatted /= 1e3;
}
const char prefixes[8] = { ' ', 'K', 'M', 'G', 'T', 'P', 'E', '?' };
// Chose matching SI prefix
@@ -345,7 +345,7 @@ const char __attribute__ ((const)) *get_ordinal_suffix(unsigned int number)
// For example: 2nd, 7th, 20th, 23rd, 52nd, 135th, 301st BUT 311th (covered above)
}
// Converts a buffer of specified lenth to ASCII representation as it was a C
// Converts a buffer of specified length to ASCII representation as it was a C
// string literal. Returns how much bytes from source was processed
// Inspired by https://stackoverflow.com/a/56123950
int binbuf_to_escaped_C_literal(const char *src_buf, size_t src_sz,
+1 -1
View File
@@ -16,7 +16,7 @@
void init_FTL_log(void);
void log_counter_info(void);
void format_memory_size(char prefix[2], unsigned long long int bytes,
double * const formated);
double * const formatted);
void format_time(char buffer[42], unsigned long seconds, double milliseconds);
const char *get_FTL_version(void) __attribute__ ((malloc));
void log_FTL_version(bool crashreport);
-4
View File
@@ -14,9 +14,6 @@
// TYPE_MAX
#include "datastructure.h"
// assert_sizeof
#include "static_assert.h"
void initOverTime(void);
#define getOverTimeID(timestamp) _getOverTimeID(timestamp, __FILE__, __LINE__)
@@ -38,7 +35,6 @@ typedef struct {
int forwarded;
time_t timestamp;
} overTimeData;
ASSERT_SIZEOF(overTimeData, 32, 24, 24);
extern overTimeData *overTime;
-5
View File
@@ -24,9 +24,6 @@ extern const char *regextype[];
#include <regex.h>
#endif
// assert_sizeof
#include "static_assert.h"
#include <netinet/in.h>
typedef struct {
@@ -46,8 +43,6 @@ typedef struct {
regex_t regex;
} regexData;
ASSERT_SIZEOF(regexData, 56, 44, 44);
unsigned int get_num_regex(const enum regex_type regexid) __attribute__((pure));
int match_regex(const char *input, DNSCacheData* dns_cache, const int clientID,
const enum regex_type regexid, const bool regextest);
+3 -3
View File
@@ -196,11 +196,11 @@ bool insetupVarsArray(const char * str)
if(setupVarsArray[i][0] == '*')
{
// Copying strlen-1 chars into buffer of size strlen: OK
size_t lenght = strlen(setupVarsArray[i]);
char * domain = calloc(lenght, sizeof(char));
size_t length = strlen(setupVarsArray[i]);
char * domain = calloc(length, sizeof(char));
if(domain == NULL) return false;
// strncat() NULL-terminates the copied string (strncpy() doesn't!)
strncat(domain, setupVarsArray[i]+1, lenght-1);
strncat(domain, setupVarsArray[i]+1, length-1);
if(strstr(str, domain) != NULL)
{
+5 -5
View File
@@ -117,12 +117,12 @@ static int get_dev_shm_usage(char buffer[64])
// Generate human-readable "used by FTL" size
char prefix_FTL[2] = { 0 };
double formated_FTL = 0.0;
format_memory_size(prefix_FTL, used_shmem, &formated_FTL);
double formatted_FTL = 0.0;
format_memory_size(prefix_FTL, used_shmem, &formatted_FTL);
// Print result into buffer passed to this subroutine
snprintf(buffer, 64, "%s, FTL uses %.1f%sB",
buffer2, formated_FTL, prefix_FTL);
buffer2, formatted_FTL, prefix_FTL);
// Return percentage
return percentage;
@@ -561,14 +561,14 @@ bool init_shmem(bool create_new)
return true;
}
// CHOWN all shared memory objects to suppplied user/group
// CHOWN all shared memory objects to supplied user/group
void chown_all_shmem(struct passwd *ent_pw)
{
for(unsigned int i = 0; i < NUM_SHMEM; i++)
chown_shmem(sharedMemories[i], ent_pw);
}
// Destory mutex and, subsequently, delete all shared memory objects
// Destroy mutex and, subsequently, delete all shared memory objects
void destroy_shmem(void)
{
// First, we destroy the mutex
-6
View File
@@ -18,22 +18,17 @@
// TYPE_MAX
#include "datastructure.h"
// assert_sizeof
#include "static_assert.h"
typedef struct {
const char *name;
size_t size;
void *ptr;
} SharedMemory;
ASSERT_SIZEOF(SharedMemory, 24, 12, 12);
typedef struct {
int version;
unsigned int global_shm_counter;
unsigned int next_str_pos;
} ShmSettings;
ASSERT_SIZEOF(ShmSettings, 12, 12, 12);
typedef struct {
int queries;
@@ -54,7 +49,6 @@ typedef struct {
int status[QUERY_STATUS_MAX];
int reply[QUERY_REPLY_MAX];
} countersStruct;
ASSERT_SIZEOF(countersStruct, 244, 244, 244);
extern countersStruct *counters;
+2 -2
View File
@@ -51,7 +51,7 @@ static void print_addr2line(const char *symbol, const void *address, const int j
if(strstr(symbol, BINARY_NAME) == NULL)
return;
// Find first occurence of '(' or ' ' in the obtaned symbol string and
// Find first occurrence of '(' or ' ' in the obtaned symbol string and
// assume everything before that is the file name. (Don't go beyond the
// string terminator \0)
int p = 0;
@@ -185,7 +185,7 @@ static void __attribute__((noreturn)) signal_handler(int sig, siginfo_t *si, voi
switch (si->si_code)
{
case BUS_ADRALN: logg(" with code: BUS_ADRALN (Invalid address alignment)"); break;
case BUS_ADRERR: logg(" with code: BUS_ADRERR (Non-existant physical address)"); break;
case BUS_ADRERR: logg(" with code: BUS_ADRERR (Non-existent physical address)"); break;
case BUS_OBJERR: logg(" with code: BUS_OBJERR (Object specific hardware error)"); break;
case BUS_MCEERR_AR: logg(" with code: BUS_MCEERR_AR (Hardware memory error: action required)"); break;
case BUS_MCEERR_AO: logg(" with code: BUS_MCEERR_AO (Hardware memory error: action optional)"); break;
-27
View File
@@ -1,27 +0,0 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2021 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Struct size assertion tool
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#include <assert.h>
#define STATIC_ASSERT(OBJECT, EXPECTED) \
static_assert(sizeof(OBJECT) == EXPECTED , "Expected size of " #OBJECT " is " #EXPECTED " on this architecture.");
// Check based on detected architecture
#if defined(__x86_64__) || defined(__aarch64__)
#define ASSERT_SIZEOF(OBJECT, SIZE64, SIZE32, SIZEARM) \
STATIC_ASSERT(OBJECT, SIZE64)
#elif defined(__i386__) || defined(__mips__) // issue #290
#define ASSERT_SIZEOF(OBJECT, SIZE64, SIZE32, SIZEARM) \
STATIC_ASSERT(OBJECT, SIZE32)
#elif defined(__arm__)
#define ASSERT_SIZEOF(OBJECT, SIZE64, SIZE32, SIZEARM) \
STATIC_ASSERT(OBJECT, SIZEARM)
#endif
+49
View File
@@ -0,0 +1,49 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2022 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Struct size checking routines
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#include "struct_size.h"
#include <stdio.h>
int check_one_struct(const char *struct_name, const size_t found_size, const size_t size64, const size_t size32)
{
#if defined(__x86_64__)
const size_t expected_size = size64;
const char *arch = "x86_64";
#elif defined(__aarch64__)
const size_t expected_size = size64;
const char *arch = "aarch64";
#elif defined(__i386__)
const size_t expected_size = size32;
const char *arch = "i386";
#elif defined(__mips__) // issue #290
const size_t expected_size = size32;
const char *arch = "mips";
#elif defined(__arm__)
const size_t expected_size = size32;
const char *arch = "arm";
#else
const size_t expected_size = 0;
const char *arch = NULL;
#endif
// Check struct size meets expectation
if(found_size == expected_size)
return 0;
// Size mismatch
if(arch)
printf("WARNING: sizeof(%s) should be %zu on %s but is %zu\n",
struct_name, expected_size, arch, found_size);
else
printf("WARNING: Unknown architecture, sizeof(%s) = %zu\n",
struct_name, found_size);
return 1;
}
+18
View File
@@ -0,0 +1,18 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2022 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Struct size checking prototypes
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#ifndef STRUCT_SIZE_HEADER
#define STRUCT_SIZE_HEADER
// type size_t
#include <stddef.h>
int check_one_struct(const char *struct_name, const size_t found_size, const size_t size64, const size_t size32);
#endif // STRUCT_SIZE_HEADER
+1 -1
View File
@@ -26,7 +26,7 @@ int FTLaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, const char
// incoming signal
while(ret < 0 && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret < 0)
logg("WARN: Could not accept() in %s() (%s:%i): %s",
+2 -2
View File
@@ -28,9 +28,9 @@ FILE *FTLfopen(const char *pathname, const char *mode, const char *file, const c
// incoming signal
while(file_ptr == NULL && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
// The already_writing coutner prevents a possible infinite loop
// The already_writing counter prevents a possible infinite loop
if(file_ptr == NULL && (already_writing++) == 1)
logg("WARN: Could not fopen(\"%s\", \"%s\") in %s() (%s:%i): %s",
pathname, mode, func, file, line, strerror(errno));
+1 -1
View File
@@ -27,7 +27,7 @@ int FTLfallocate(const int fd, const off_t offset, const off_t len, const char *
// interruption by an incoming signal
while(ret == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret > 0)
logg("WARN: Could not fallocate() in %s() (%s:%i): %s",
+1 -1
View File
@@ -28,7 +28,7 @@ int FTLpthread_mutex_lock(pthread_mutex_t *__mutex, const char *file, const char
// incoming signal
while(ret < 0 && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret < 0)
logg("WARN: Could not pthread_mutex_lock() in %s() (%s:%i): %s",
+1 -1
View File
@@ -28,7 +28,7 @@ ssize_t FTLrecv(int sockfd, void *buf, size_t len, int flags, const char *file,
// incoming signal
while(ret < 0 && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret < 0)
logg("WARN: Could not recv() in %s() (%s:%i): %s",
+1 -1
View File
@@ -29,7 +29,7 @@ ssize_t FTLrecvfrom(int sockfd, void *buf, size_t len, int flags, struct sockadd
// incoming signal
while(ret < 0 && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret < 0)
logg("WARN: Could not recvfrom() in %s() (%s:%i): %s",
+1 -1
View File
@@ -28,7 +28,7 @@ int FTLselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
// incoming signal
while(ret < 0 && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret < 0)
logg("WARN: Could not select() in %s() (%s:%i): %s",
+1 -1
View File
@@ -29,7 +29,7 @@ ssize_t FTLsendto(int sockfd, void *buf, size_t len, int flags, const struct soc
// incoming signal
while(ret < 0 && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(ret < 0)
logg("WARN: Could not sendto() in %s() (%s:%i): %s",
+1 -1
View File
@@ -152,7 +152,7 @@ int FTLvfprintf(FILE *stream, const char *file, const char *func, const int line
// to an interruption by an incoming signal
while(_buffer < buffer && errno == EINTR);
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(_buffer < buffer)
{
+1 -1
View File
@@ -36,7 +36,7 @@ ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const
// (b) the last write() call failed due to an interruption by an incoming signal
while((written < total && errno == 0) || (ret < 0 && errno == EINTR));
// Final error checking (may have faild for some other reason then an
// Final error checking (may have failed for some other reason then an
// EINTR = interrupted system call)
if(written < total)
logg("WARN: Could not write() everything in %s() [%s:%i]: %s",
-3
View File
@@ -18,8 +18,6 @@
#include <stdbool.h>
// type sqlite3_stmt
#include "database/sqlite3.h"
// assert_sizeof
#include "static_assert.h"
#define VEC_ALLOC_STEP 10u
@@ -29,7 +27,6 @@ typedef struct sqlite3_stmt_vec {
sqlite3_stmt *(*get)(struct sqlite3_stmt_vec *, unsigned int);
void (*set)(struct sqlite3_stmt_vec *, unsigned int, sqlite3_stmt*);
} sqlite3_stmt_vec;
ASSERT_SIZEOF(sqlite3_stmt_vec, 32, 16, 16);
sqlite3_stmt_vec *new_sqlite3_stmt_vec(unsigned int initial_size);
void set_sqlite3_stmt_vec(sqlite3_stmt_vec *v, unsigned int index, sqlite3_stmt* item);
+1 -1
View File
@@ -56,7 +56,7 @@ check_FP_arch() {
check_file() {
filedetails="$(file -b pihole-FTL | sed "s/, BuildID[^,]*//g")"
if [[ "${filedetails}" != "${1}" ]]; then
echo "Wrong binary clasification"
echo "Wrong binary classification"
echo "Expected: ${1}"
echo "Found: ${filedetails}"
exit 1
+3 -3
View File
@@ -6,14 +6,14 @@ log-facility=/var/log/pihole.log
dnssec
trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D
# Explicity specify the local powerDNS recursor as forward destination for .ftl
# Explicitly specify the local powerDNS recursor as forward destination for .ftl
# This ensures FTL knows that ftl. is a local zone for which no DNSSEC
# validation should be done. Otherwise, we'd get BOGUS for everything as the
# root servers would tell us that ftl. does not exist
server=/ftl/127.0.0.1#5555
# Send the HTTPS/SVCB queries to the authorative server without detour over the
# recursor because the latter returns SEVFAIL (connection between authorative
# Send the HTTPS/SVCB queries to the authoritative server without detour over the
# recursor because the latter returns SEVFAIL (connection between authoritative
# server and recursor is not encrypted)
server=/https.ftl/127.0.0.1#5554
server=/svcb.ftl/127.0.0.1#5554
+1 -1
View File
@@ -2,7 +2,7 @@
# (c) 2021 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
# Pi-hole testing environment configuration (authorative server)
# Pi-hole testing environment configuration (authoritative server)
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
+1 -1
View File
@@ -10,5 +10,5 @@
# Local DNS address and port
local-address=127.0.0.1:5555
# Use authorative server for ftl. and arpa. zones
# Use authoritative server for ftl. and arpa. zones
forward-zones=ftl=127.0.0.1:5554,168.192.in-addr.arpa=127.0.0.1:5554,ip6.arpa=127.0.0.1:5554
+6
View File
@@ -1097,6 +1097,12 @@
[[ ${lines[0]} == *"using ${compiler_version}"* ]]
}
@test "Struct sizes are as expected" {
run bash -c './pihole-FTL --check-structs'
printf "%s\n" "${lines[@]}"
[[ $status == 0 ]]
}
@test "No errors on setting busy handlers for the databases" {
run bash -c 'grep -c "Cannot set busy handler" /var/log/pihole-FTL.log'
printf "%s\n" "${lines[@]}"