From b83fcadf6c321bcac00bcc0d3cc80adb64562d7a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 12 May 2024 21:01:24 +0200 Subject: [PATCH 01/22] Remove all-in build option - we aren't using it in Pi-hole v6.0 Signed-off-by: DL6ER --- src/CMakeLists.txt | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 185ba5dc..72c99c27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -316,24 +316,6 @@ else() message(STATUS "Building FTL with readline support: NO") endif() -# Do we want to compile an all-in FTL version? -if(DEFINED ENV{CI_ARCH}) - if($ENV{CI_ARCH} STREQUAL "x86_64_full") - add_definitions(-DDNSMASQ_ALL_OPTS) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) - find_package(DBus REQUIRED) - # Use results of find_package() call. - include_directories(${DBUS_INCLUDE_DIRS}) - target_link_libraries(pihole-FTL ${DBUS_LIBRARIES}) - find_library(LIBMNL mnl) - find_library(LIBNFTNL nftnl) - find_library(LIBNFTABLES nftables) - find_library(LIBNFNETLINK nfnetlink) - find_library(LIBNETFILTER_CONNTRACK netfilter_conntrack) - target_link_libraries(pihole-FTL ${LIBMNL} ${LIBNFTABLES} ${LIBNFTNL} ${LIBNFNETLINK} ${LIBNETFILTER_CONNTRACK}) - endif() -endif() - if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE) endif() From fccbe2bee4c14c4d1b0a6f19d6a91c02bec76922 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 12 May 2024 21:08:39 +0200 Subject: [PATCH 02/22] Add missing #include Signed-off-by: DL6ER --- src/api/teleporter.c | 2 ++ src/files.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/api/teleporter.c b/src/api/teleporter.c index 5e4a3b5a..986f6bc4 100644 --- a/src/api/teleporter.c +++ b/src/api/teleporter.c @@ -25,6 +25,8 @@ #include "database/common.h" // MAX_ROTATIONS #include "files.h" +//basename() +#include #define MAXFILESIZE (50u*1024*1024) diff --git a/src/files.c b/src/files.c index 5e1f57c0..cb5799fd 100644 --- a/src/files.c +++ b/src/files.c @@ -33,6 +33,9 @@ // PRIu64 #include +//basename() +#include + // chmod_file() changes the file mode bits of a given file (relative // to the directory file descriptor) according to mode. mode is an // octal number representing the bit pattern for the new mode bits From 91b1ced3ab1e2b5ad02268262b35d7238a5b3dc5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 12 May 2024 21:10:54 +0200 Subject: [PATCH 03/22] Fix use-after-free warning Signed-off-by: DL6ER --- src/tre-regex/xmalloc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tre-regex/xmalloc.c b/src/tre-regex/xmalloc.c index 3459d2d9..afe1bd14 100644 --- a/src/tre-regex/xmalloc.c +++ b/src/tre-regex/xmalloc.c @@ -340,6 +340,7 @@ xrealloc_impl(void *ptr, size_t new_size, const char *file, int line, new_ptr = realloc(ptr, new_size); if (new_ptr != NULL) { + ptr = NULL; hash_table_del(xmalloc_table, ptr); hash_table_add(xmalloc_table, new_ptr, (int)new_size, file, line, func); } From 55258150c1e35e19b35d6d39153ba6e4a0cb92bb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 12 May 2024 21:40:50 +0200 Subject: [PATCH 04/22] Allocate memory for basename() Signed-off-by: DL6ER --- src/api/teleporter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/teleporter.c b/src/api/teleporter.c index 986f6bc4..68c870ae 100644 --- a/src/api/teleporter.c +++ b/src/api/teleporter.c @@ -797,8 +797,8 @@ static int process_received_tar_gz(struct ftl_conn *api, struct upload_data *dat // restore on restart for(unsigned int i = MAX_ROTATIONS; i > 0; i--) { - const char *fname = GLOBALTOMLPATH; - const char *filename = basename(fname); + char *fname = strdup(GLOBALTOMLPATH); + char *filename = basename(fname); // extra 6 bytes is enough space for up to 999 rotations ("/", ".", "\0", "999") const size_t buflen = strlen(filename) + strlen(BACKUP_DIR) + 6; char *path = calloc(buflen, sizeof(char)); @@ -807,6 +807,8 @@ static int process_received_tar_gz(struct ftl_conn *api, struct upload_data *dat // Remove file (if it exists) if(remove(path) != 0 && errno != ENOENT) log_err("Unable to remove file \"%s\": %s", path, strerror(errno)); + + free(fname); } // Free allocated memory From 32de390b002b06ada79489449f2dbe8d37b66761 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 15 May 2024 20:41:52 +0200 Subject: [PATCH 05/22] Add Clang compiler support, tested with Clang 14.0.0 (Ubuntu 22.04.3 LTS), Clang 16.0.2 (Alpine 3.18), and Clang 17.0.6 (Alping Edge) Signed-off-by: DL6ER --- build.sh | 7 +++++++ src/CMakeLists.txt | 39 +++++++++++++++++++++++++++--------- src/api/auth.h | 2 +- src/api/config.c | 4 ++-- src/api/dhcp.c | 2 +- src/api/queries.c | 4 ++++ src/api/stats.c | 2 -- src/api/stats_database.c | 2 -- src/config/cli.h | 2 +- src/config/legacy_reader.c | 29 ++++++++++++++++----------- src/config/password.c | 5 +---- src/config/validator.c | 12 ----------- src/database/CMakeLists.txt | 4 ++++ src/database/common.c | 2 ++ src/database/common.h | 2 +- src/database/query-table.c | 2 +- src/database/sqlite3-ext.c | 2 +- src/dnsmasq/CMakeLists.txt | 6 +++++- src/dnsmasq_interface.c | 13 +++++++----- src/edns0.c | 2 +- src/enums.h | 1 + src/events.h | 2 +- src/log.c | 7 ++++--- src/log.h | 17 ++++++++-------- src/lua/CMakeLists.txt | 4 +++- src/lua/ftl_lua.c | 2 ++ src/lua/ftl_lua.h | 2 +- src/procps.h | 2 +- src/resolve.c | 6 +++--- src/shmem.c | 10 ++++++++- src/struct_size.h | 2 +- src/syscalls/accept.c | 2 +- src/syscalls/recv.c | 2 +- src/syscalls/recvfrom.c | 2 +- src/syscalls/select.c | 2 +- src/syscalls/sendto.c | 2 +- src/syscalls/strdup.c | 2 +- src/syscalls/syscalls.h | 16 +++++++-------- src/syscalls/write.c | 2 +- src/tools/arp-scan.c | 4 ++-- src/tools/dhcp-discover.c | 19 ++++++++---------- src/tre-regex/CMakeLists.txt | 4 +++- src/webserver/lua_web.h | 2 +- src/webserver/webserver.c | 3 ++- src/webserver/webserver.h | 2 +- src/zip/gzip.c | 16 +++++++++++---- src/zip/miniz/CMakeLists.txt | 1 + src/zip/miniz/miniz.h | 2 +- src/zip/tar.c | 2 +- src/zip/tar.h | 2 +- 50 files changed, 168 insertions(+), 117 deletions(-) diff --git a/build.sh b/build.sh index b83062a4..b92062d1 100755 --- a/build.sh +++ b/build.sh @@ -23,6 +23,7 @@ do "-C" | "CLEAN" ) clean=1 && nobuild=1;; "-i" | "install" ) install=1;; "-t" | "test" ) test=1;; + "clang" ) clang=1;; "ci" ) builddir="cmake_ci/";; esac done @@ -60,6 +61,12 @@ for scriptname in src/lua/scripts/*.lua; do fi done +# Set compiler to clang if requested +if [[ -n "${clang}" ]]; then + export CC=clang + export CXX=clang++ +fi + # Configure build, pass CMake CACHE entries if present # Wrap multiple options in "" as first argument to ./build.sh: # ./build.sh "-DA=1 -DB=2" install diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 185ba5dc..9e3c35bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,8 +53,10 @@ set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -D # -Wl,-z,now: Disable lazy binding # -Wl,-z,relro: Read-only segments after relocation # -fno-common: Emit globals without explicit initializer from `.bss` to `.data`. This causes GCC to reject multiple definitions of global variables. This is the new default from GCC-10 on. -set(HARDENING_FLAGS "-fstack-protector-strong -Wp,-D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -fexceptions -funwind-tables -fasynchronous-unwind-tables -Wl,-z,defs -Wl,-z,now -Wl,-z,relro -fno-common") -set(DEBUG_FLAGS "-rdynamic -fno-omit-frame-pointer") +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(HARDENING_FLAGS "-fstack-protector-strong -Wp,-D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -fexceptions -funwind-tables -fasynchronous-unwind-tables -Wl,-z,defs -Wl,-z,now -Wl,-z,relro -fno-common") + set(DEBUG_FLAGS "-rdynamic -fno-omit-frame-pointer") +endif() # -Wall: This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options. # -Wextra: This enables some extra warning flags that are not enabled by -Wall. @@ -155,11 +157,25 @@ else() set(EXTRAWARN_GCC13 "") endif() -set(EXTRAWARN "${EXTRAWARN_GCC6} \ - ${EXTRAWARN_GCC7} \ - ${EXTRAWARN_GCC8} \ - ${EXTRAWARN_GCC12} \ - ${EXTRAWARN_GCC13}") +# Set extrawarn flags if CC is GCC +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(EXTRAWARN "${EXTRAWARN_GCC6} \ + ${EXTRAWARN_GCC7} \ + ${EXTRAWARN_GCC8} \ + ${EXTRAWARN_GCC12} \ + ${EXTRAWARN_GCC13}") +elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(EXTRAWARN "-Wnewline-eof \ + -Wno-dangling-else \ + -Wno-gnu-zero-variadic-macro-arguments \ + -Wno-gnu-variable-sized-type-not-at-end \ + -Wno-declaration-after-statement \ + -Wno-reserved-identifier \ + -Wno-reserved-macro-identifier") +else() + message(WARNING "Unknown compiler, not setting warnings flags") + set(EXTRAWARN "") +endif() # Remove extra spaces from EXTRAWARN string(REGEX REPLACE " +" " " EXTRAWARN "${EXTRAWARN}") @@ -185,11 +201,14 @@ else() message(STATUS "Compiling dynamically linked executable") endif() # -pie -fPIE: (Dynamic) position independent executable -set(HARDENING_FLAGS "${HARDENING_FLAGS} -pie -fPIE") + +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(HARDENING_FLAGS "${HARDENING_FLAGS} -pie -fPIE") +endif() # -FILE_OFFSET_BITS=64: used by stat(). Avoids problems with files > 2 GB on 32bit machines # We define HAVE_POLL_H as this is needed for the musl builds to succeed -set(CMAKE_C_FLAGS "-pipe ${WARN_FLAGS} -D_FILE_OFFSET_BITS=64 ${HARDENING_FLAGS} ${DEBUG_FLAGS} ${CMAKE_C_FLAGS} -DHAVE_POLL_H ${SQLITE_DEFINES}") +set(CMAKE_C_FLAGS "-std=c99 -pipe ${WARN_FLAGS} -D_FILE_OFFSET_BITS=64 ${HARDENING_FLAGS} ${DEBUG_FLAGS} ${CMAKE_C_FLAGS} -DHAVE_POLL_H ${SQLITE_DEFINES}") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") @@ -279,7 +298,7 @@ add_executable(pihole-FTL if(STATIC) set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_START_STATIC ON) set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_END_STATIC ON) - target_link_libraries(pihole-FTL -static-libgcc -static -pie) + target_link_libraries(pihole-FTL -static-libgcc -static) else() find_library(LIBMATH m) target_link_libraries(pihole-FTL ${LIBMATH}) diff --git a/src/api/auth.h b/src/api/auth.h index 53663026..5028b6c8 100644 --- a/src/api/auth.h +++ b/src/api/auth.h @@ -60,4 +60,4 @@ struct session { char csrf[SID_SIZE]; }; -#endif // AUTH_H \ No newline at end of file +#endif // AUTH_H diff --git a/src/api/config.c b/src/api/config.c index c998823b..f413e502 100644 --- a/src/api/config.c +++ b/src/api/config.c @@ -238,7 +238,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem, struct // 1. Check it is a number // 2. Check the number is within the allowed range for the given data type if(!cJSON_IsNumber(elem) || - elem->valuedouble < LONG_MIN || elem->valuedouble > LONG_MAX) + elem->valuedouble < (double)LONG_MIN || elem->valuedouble > (double)LONG_MAX) return "not of type long"; // Set item conf_item->v.l = elem->valuedouble; @@ -250,7 +250,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem, struct // 1. Check it is a number // 2. Check the number is within the allowed range for the given data type if(!cJSON_IsNumber(elem) || - elem->valuedouble < 0 || elem->valuedouble > ULONG_MAX) + elem->valuedouble < 0 || elem->valuedouble > (double)ULONG_MAX) return "not of type unsigned long"; // Set item conf_item->v.ul = elem->valuedouble; diff --git a/src/api/dhcp.c b/src/api/dhcp.c index 16898ca9..4e9e67af 100644 --- a/src/api/dhcp.c +++ b/src/api/dhcp.c @@ -110,4 +110,4 @@ int api_dhcp_leases_DELETE(struct ftl_conn *api) // - 404 Not Found (if no lease was found) cJSON *json = JSON_NEW_OBJECT(); JSON_SEND_OBJECT_CODE(json, found ? 204 : 404); -} \ No newline at end of file +} diff --git a/src/api/queries.c b/src/api/queries.c index 82735726..eb16529f 100644 --- a/src/api/queries.c +++ b/src/api/queries.c @@ -432,10 +432,14 @@ int api_queries(struct ftl_conn *api) // Encoded URI string: %5B = [ and %5D = ] if(GET_VAR(sort_col_id, sort_col, api->request->query_string) > 0) + { log_debug(DEBUG_API, "Sorting by column %s (%s)", sort_col, sort_dir); + } else + { log_warn("Sorting by column %d (%s) requested, but column name not found", sort_column, sort_dir); + } } // Column searching? diff --git a/src/api/stats.c b/src/api/stats.c index 86de44c5..b272e768 100644 --- a/src/api/stats.c +++ b/src/api/stats.c @@ -458,7 +458,6 @@ int api_stats_top_clients(struct ftl_conn *api) int api_stats_upstreams(struct ftl_conn *api) { - unsigned int totalcount = 0; const int upstreams = counters->upstreams; int *temparray = calloc(2*upstreams, sizeof(int)); if(temparray == NULL) @@ -480,7 +479,6 @@ int api_stats_upstreams(struct ftl_conn *api) temparray[2*added_upstreams + 0] = upstreamID; temparray[2*added_upstreams + 1] = upstream->count; - totalcount += upstream->count; added_upstreams++; } diff --git a/src/api/stats_database.c b/src/api/stats_database.c index b4309f07..5a30b105 100644 --- a/src/api/stats_database.c +++ b/src/api/stats_database.c @@ -514,13 +514,11 @@ int api_history_database_clients(struct ftl_conn *api) // Loop over clients and accumulate results cJSON *clients = JSON_NEW_OBJECT(); - unsigned int num_clients = 0; while((rc = sqlite3_step(stmt)) == SQLITE_ROW) { cJSON *item = JSON_NEW_OBJECT(); JSON_COPY_STR_TO_OBJECT(item, "name", sqlite3_column_text(stmt, 2)); JSON_ADD_ITEM_TO_OBJECT(clients, (const char*)sqlite3_column_text(stmt, 1), item); - num_clients++; } sqlite3_finalize(stmt); diff --git a/src/config/cli.h b/src/config/cli.h index 4cf4cc31..c9398bcf 100644 --- a/src/config/cli.h +++ b/src/config/cli.h @@ -13,4 +13,4 @@ int set_config_from_CLI(const char *key, const char *value); int get_config_from_CLI(const char *key, const bool quiet); -#endif //CONFIG_CLI_H \ No newline at end of file +#endif //CONFIG_CLI_H diff --git a/src/config/legacy_reader.c b/src/config/legacy_reader.c index 857bcc2b..06173fea 100644 --- a/src/config/legacy_reader.c +++ b/src/config/legacy_reader.c @@ -77,9 +77,12 @@ bool getLogFilePathLegacy(struct config *conf, FILE *fp) strerror(errno), errno); exit(EXIT_FAILURE); } + + fclose(fp); + return true; } // Use sscanf() to obtain filename from config file parameter only if buffer != NULL - else if(sscanf(buffer, "%127ms", &val_buffer) == 0) + else if((val_buffer = calloc(128, sizeof(char))) == NULL || sscanf(buffer, "%127s", val_buffer) == 0) { // Free previously allocated memory (if any) if(conf->files.log.ftl.t == CONF_STRING_ALLOCATED) @@ -91,7 +94,8 @@ bool getLogFilePathLegacy(struct config *conf, FILE *fp) log_info("Using syslog facility"); } - if(val_buffer) + // Set string if memory allocation was successful and a value was read + if(val_buffer != NULL && strlen(val_buffer) > 0) { // Free previously allocated memory (if any) if(conf->files.log.ftl.t == CONF_STRING_ALLOCATED) @@ -589,35 +593,36 @@ const char *readFTLlegacy(struct config *conf) return path; } -static char* getPath(FILE* fp, const char *option, char *ptr) +static char *getPath(FILE* fp, const char *option, char *path_default) { // This subroutine is used to read paths from pihole-FTL.conf - // fp: File ptr to opened and readable config file - // option: Option string ("key") to try to read - // ptr: Location where read (or default) parameter is stored + // fp: File path to opened and readable config file + // option: Option string ("key") to try to read + // path_default: Location where read (or default) parameter is stored char *buffer = parseFTLconf(fp, option); errno = 0; // Use sscanf() to obtain filename from config file parameter only if buffer != NULL - if(buffer == NULL || sscanf(buffer, "%127ms", &ptr) != 1) + char *val_ptr = calloc(128, sizeof(char)); + if(buffer == NULL || sscanf(buffer, "%127s", val_ptr) != 1) { // Use standard path if no custom path was obtained from the config file - return ptr; + return path_default; } // Test if memory allocation was successful - if(ptr == NULL) + if(val_ptr == NULL) { log_crit("Allocating memory for %s failed (%s, %i). Exiting.", option, strerror(errno), errno); exit(EXIT_FAILURE); } - else if(strlen(ptr) == 0) + else if(strlen(val_ptr) == 0) { log_info(" %s: Empty path is not possible, using default", option); } - return ptr; + return val_ptr; } static char *parseFTLconf(FILE *fp, const char * key) @@ -703,7 +708,7 @@ void releaseConfigMemory(void) void init_config_mutex(void) { // Initialize the lock attributes - pthread_mutexattr_t lock_attr = {}; + pthread_mutexattr_t lock_attr; pthread_mutexattr_init(&lock_attr); // Initialize the lock diff --git a/src/config/password.c b/src/config/password.c index d97df6d2..c1231ed7 100644 --- a/src/config/password.c +++ b/src/config/password.c @@ -315,10 +315,7 @@ char * __attribute__((malloc)) create_password(const char *password) enum password_result verify_login(const char *password) { enum password_result pw = verify_password(password, config.webserver.api.pwhash.v.s, true); - if(pw == PASSWORD_CORRECT) - log_debug(DEBUG_API, "Password correct"); - else - log_debug(DEBUG_API, "Password incorrect"); + log_debug(DEBUG_API, pw == PASSWORD_CORRECT ? "Password correct" : "Password incorrect"); // Check if an application password is set and if it matches if(pw == PASSWORD_INCORRECT && diff --git a/src/config/validator.c b/src/config/validator.c index 543057d7..06b8affd 100644 --- a/src/config/validator.c +++ b/src/config/validator.c @@ -123,12 +123,6 @@ bool validate_dns_cnames(union conf_value *val, const char *key, char err[VALIDA return false; } - // Count the number of elements in the string - unsigned int elements = 1; - for(unsigned int j = 0; j < strlen(item->valuestring); j++) - if(item->valuestring[j] == ',') - elements++; - // Check if it's in the form ",[,][,]" // is optional and may be repeated char *str = strdup(item->valuestring); @@ -398,12 +392,6 @@ bool validate_dns_revServers(union conf_value *val, const char *key, char err[VA return false; } - // Count the number of elements in the string - unsigned int elements = 1; - for(unsigned int j = 0; j < strlen(item->valuestring); j++) - if(item->valuestring[j] == ',') - elements++; - // Check if it's in the form ",[/],[#]," // Mandatory elements are: , , , and // Optional elements are: [/] and [#] diff --git a/src/database/CMakeLists.txt b/src/database/CMakeLists.txt index 3a16bf9b..b0a4597d 100644 --- a/src/database/CMakeLists.txt +++ b/src/database/CMakeLists.txt @@ -20,6 +20,10 @@ set(sqlite3_sources add_library(sqlite3 OBJECT ${sqlite3_sources}) target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-sign-compare) +if (CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_compile_options(sqlite3 PRIVATE "-Wno-null-pointer-subtraction") +endif() + set(database_sources common.c common.h diff --git a/src/database/common.c b/src/database/common.c index 8d6756c2..f209a50f 100644 --- a/src/database/common.c +++ b/src/database/common.c @@ -253,11 +253,13 @@ void SQLite3LogCallback(void *pArg, int iErrCode, const char *zMsg) if(iErrCode == SQLITE_WARNING) log_warn("SQLite3: %s (%d)", zMsg, iErrCode); else if(iErrCode == SQLITE_NOTICE || iErrCode == SQLITE_SCHEMA) + { // SQLITE_SCHEMA is returned when the database schema has changed // This is not necessarily an error, as sqlite3_step() will re-prepare // the statement and try again. If it cannot, it will return an error // and this will be handled over there. log_debug(DEBUG_ANY, "SQLite3: %s (%d)", zMsg, iErrCode); + } else log_err("SQLite3: %s (%d)", zMsg, iErrCode); } diff --git a/src/database/common.h b/src/database/common.h index d2369185..5dd0c875 100644 --- a/src/database/common.h +++ b/src/database/common.h @@ -36,7 +36,7 @@ bool db_set_FTL_property(sqlite3* db, const enum ftl_table_props ID, const int v bool db_set_FTL_property_double(sqlite3* db, const enum ftl_table_props ID, const double value); /// Execute a formatted SQL query and get the return code -int dbquery(sqlite3* db, const char *format, ...) __attribute__ ((format (gnu_printf, 2, 3)));; +int dbquery(sqlite3* db, const char *format, ...) __attribute__ ((format (printf, 2, 3)));; #define dbopen(readonly, create) _dbopen(readonly, create, __FUNCTION__, __LINE__, __FILE__) sqlite3 *_dbopen(const bool readonly, const bool create, const char *func, const int line, const char *file) __attribute__((warn_unused_result)); diff --git a/src/database/query-table.c b/src/database/query-table.c index f66d5152..40949bc2 100644 --- a/src/database/query-table.c +++ b/src/database/query-table.c @@ -1046,7 +1046,7 @@ void DB_read_queries(void) (buffer = (const char *)sqlite3_column_text(stmt, 6)) != NULL) { // Get IP address and port of upstream destination - char serv_addr[INET6_ADDRSTRLEN] = { 0 }; + char serv_addr[INET6_ADDRSTRLEN + 1] = { 0 }; unsigned int serv_port = 53; // We limit the number of bytes written into the serv_addr buffer // to prevent buffer overflows. If there is no port available in diff --git a/src/database/sqlite3-ext.c b/src/database/sqlite3-ext.c index f52ef029..e3e28498 100644 --- a/src/database/sqlite3-ext.c +++ b/src/database/sqlite3-ext.c @@ -215,4 +215,4 @@ int sqlite3_pihole_extensions_init(sqlite3 *db, const char **pzErrMsg, const str } return rc; -} \ No newline at end of file +} diff --git a/src/dnsmasq/CMakeLists.txt b/src/dnsmasq/CMakeLists.txt index 2497bc72..9caab62f 100644 --- a/src/dnsmasq/CMakeLists.txt +++ b/src/dnsmasq/CMakeLists.txt @@ -65,5 +65,9 @@ set(sources add_library(dnsmasq OBJECT ${sources}) target_compile_definitions(dnsmasq PRIVATE VERSION=\"${DNSMASQ_VERSION}\") target_compile_definitions(dnsmasq PRIVATE CONFFILE=\"/etc/pihole/dnsmasq.conf\") -target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized) +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized) +elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_compile_options(dnsmasq PRIVATE -Wno-gnu-variable-sized-type-not-at-end -Wno-sign-compare -Wno-deprecated-non-prototype) +endif() target_include_directories(dnsmasq PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/lua) diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index f816abb6..d17991bf 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -198,10 +198,7 @@ size_t _FTL_make_answer(struct dns_header *header, char *limit, const size_t len return 0; // Debug logging - if(*ede != EDE_UNSET) - log_debug(DEBUG_QUERIES, "Preparing reply for \"%s\", EDE: %s (%d)", name, edestr(*ede), *ede); - else - log_debug(DEBUG_QUERIES, "Preparing reply for \"%s\", EDE: N/A", name); + log_debug(DEBUG_QUERIES, "Preparing reply for \"%s\", EDE: %s (%d)", name, *ede != EDE_UNSET ? edestr(*ede) : "N/A", *ede); // Get question type int qtype, flags = 0; @@ -844,13 +841,17 @@ bool _FTL_new_query(const unsigned int flags, const char *name, if(config.debug.arp.v.b) { if(client->hwlen == 6) + { log_debug(DEBUG_ARP, "find_mac(\"%s\") returned hardware address " "%02X:%02X:%02X:%02X:%02X:%02X", clientIP, client->hwaddr[0], client->hwaddr[1], client->hwaddr[2], client->hwaddr[3], client->hwaddr[4], client->hwaddr[5]); + } else + { log_debug(DEBUG_ARP, "find_mac(\"%s\") returned %i bytes of data", clientIP, client->hwlen); + } } } @@ -1997,10 +1998,12 @@ static void FTL_reply(const unsigned int flags, const char *name, const union al dispname = "."; if(cached || last_server.sa.sa_family == 0) + { // Log cache or upstream reply from unknown source log_debug(DEBUG_QUERIES, "**** got %s%s reply: %s is %s (ID %i, %s:%i)", stale ? "stale ": "", cached ? "cache" : "upstream", dispname, answer, id, file, line); + } else { char ip[ADDRSTRLEN+1] = { 0 }; @@ -3561,4 +3564,4 @@ void FTL_connection_error(const char *reason, const union mysockaddr *addr) if(server != NULL) free(server); } -} \ No newline at end of file +} diff --git a/src/edns0.c b/src/edns0.c index a310a3d9..8f27a184 100644 --- a/src/edns0.c +++ b/src/edns0.c @@ -419,4 +419,4 @@ void FTL_parse_pseudoheaders(unsigned char *pheader, const size_t plen) p += optlen; } } -} \ No newline at end of file +} diff --git a/src/enums.h b/src/enums.h index ab09498a..09769a9c 100644 --- a/src/enums.h +++ b/src/enums.h @@ -134,6 +134,7 @@ enum domain_client_status { } __attribute__ ((packed)); enum debug_flag { + DEBUG_NONE = 0, DEBUG_DATABASE = 1, DEBUG_NETWORKING, DEBUG_LOCKS, diff --git a/src/events.h b/src/events.h index ea5b7f27..3ae0a70d 100644 --- a/src/events.h +++ b/src/events.h @@ -19,4 +19,4 @@ void _set_event(const enum events event, int line, const char *function, const c #define get_and_clear_event(event) _get_and_clear_event(event, __LINE__, __FUNCTION__, __FILE__) bool _get_and_clear_event(const enum events event, int line, const char *function, const char *file); -#endif // EVENTS_H \ No newline at end of file +#endif // EVENTS_H diff --git a/src/log.c b/src/log.c index e861c922..f57004a2 100644 --- a/src/log.c +++ b/src/log.c @@ -219,12 +219,13 @@ const char *debugstr(const enum debug_flag flag) return "DEBUG_RESERVED"; case DEBUG_MAX: return "DEBUG_MAX"; + case DEBUG_NONE: // fall through default: return "DEBUG_ANY"; } } -void __attribute__ ((format (gnu_printf, 3, 4))) _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...) +void __attribute__ ((format (printf, 3, 4))) _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...) { char timestring[TIMESTR_SIZE] = ""; va_list args; @@ -321,7 +322,7 @@ void __attribute__ ((format (gnu_printf, 3, 4))) _FTL_log(const int priority, co } } -void __attribute__ ((format (gnu_printf, 1, 2))) log_web(const char *format, ...) +void __attribute__ ((format (printf, 1, 2))) log_web(const char *format, ...) { char timestring[TIMESTR_SIZE] = ""; const time_t now = time(NULL); @@ -362,7 +363,7 @@ void __attribute__ ((format (gnu_printf, 1, 2))) log_web(const char *format, ... } // Log helper activity (may be script or lua) -void FTL_log_helper(const unsigned char n, ...) +void FTL_log_helper(const unsigned int n, ...) { // Only log helper debug messages if enabled if(!(config.debug.helper.v.b)) diff --git a/src/log.h b/src/log.h index 215b0bec..d794191b 100644 --- a/src/log.h +++ b/src/log.h @@ -53,7 +53,7 @@ void log_FTL_version(bool crashreport); double double_time(void); void get_timestr(char timestring[TIMESTR_SIZE], const time_t timein, const bool millis, const bool uri_compatible); const char *debugstr(const enum debug_flag flag) __attribute__((const)); -void log_web(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2))); +void log_web(const char *format, ...) __attribute__ ((format (printf, 1, 2))); const char *get_ordinal_suffix(unsigned int number) __attribute__ ((const)); void print_FTL_version(void); unsigned int countchar(const char *str, const char c) __attribute__ ((pure)); @@ -66,14 +66,13 @@ void dnsmasq_diagnosis_warning(char *message); #define log_warn(format, ...) _FTL_log(LOG_WARNING, 0, format, ## __VA_ARGS__) #define log_notice(format, ...) _FTL_log(LOG_NOTICE, 0, format, ## __VA_ARGS__) #define log_info(format, ...) _FTL_log(LOG_INFO, 0, format, ## __VA_ARGS__) -#define log_debug(flag, format, ...)({ \ +#define log_debug(flag, format, ...) \ if(flag > -1 && flag < DEBUG_MAX && debug_flags[flag]) \ - _FTL_log(LOG_DEBUG, flag, format, ## __VA_ARGS__); \ -}) -void _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...) __attribute__ ((format (gnu_printf, 3, 4))); -void FTL_log_dnsmasq_fatal(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2))); + _FTL_log(LOG_DEBUG, flag, format, ## __VA_ARGS__) +void _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...) __attribute__ ((format (printf, 3, 4))); +void FTL_log_dnsmasq_fatal(const char *format, ...) __attribute__ ((format (printf, 1, 2))); void log_ctrl(bool vlog, bool vstdout); -void FTL_log_helper(const unsigned char n, ...); +void FTL_log_helper(const unsigned int n, ...); int binbuf_to_escaped_C_literal(const char *src_buf, size_t src_sz, char *dst_str, size_t dst_sz); @@ -84,7 +83,7 @@ int blocked_queries(void) __attribute__ ((pure)); const char *short_path(const char *full_path) __attribute__ ((pure)); // How long is each line in the FIFO buffer allowed to be? -#define MAX_MSG_FIFO 256u +#define MAX_MSG_FIFO 260u // How many messages do we keep in memory (FIFO message buffer)? // This number multiplied by MAX_MSG_FIFO (see above) gives the total buffer size @@ -97,9 +96,9 @@ bool flush_dnsmasq_log(void); typedef struct { struct { + char message[LOG_SIZE][MAX_MSG_FIFO]; unsigned int next_id; double timestamp[LOG_SIZE]; - char message[LOG_SIZE][MAX_MSG_FIFO]; const char *prio[LOG_SIZE]; } logs[FIFO_MAX]; } fifologData; diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt index 908b5a7e..e319393e 100644 --- a/src/lua/CMakeLists.txt +++ b/src/lua/CMakeLists.txt @@ -65,7 +65,9 @@ set(sources ) add_library(lua OBJECT ${sources}) -target_compile_options(lua PRIVATE -Wno-maybe-uninitialized -Wno-unused-variable -Wno-unused-value) +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + target_compile_options(lua PRIVATE -Wno-maybe-uninitialized -Wno-unused-variable -Wno-unused-value) +endif() # LUA_USE_POSIX: ensures recommended POSIX functions are used instead of # (partially obsoleted) standard C functions diff --git a/src/lua/ftl_lua.c b/src/lua/ftl_lua.c index 5f448406..0948ed06 100644 --- a/src/lua/ftl_lua.c +++ b/src/lua/ftl_lua.c @@ -20,7 +20,9 @@ #include "../files.h" // get_web_theme_str #include "../datastructure.h" +#if HAVE_READLINE #include +#endif #include #include "scripts/scripts.h" diff --git a/src/lua/ftl_lua.h b/src/lua/ftl_lua.h index 29c4cb5f..d986498a 100644 --- a/src/lua/ftl_lua.h +++ b/src/lua/ftl_lua.h @@ -26,4 +26,4 @@ extern int dolibrary (lua_State *L, char *name); void print_embedded_scripts(void); void ftl_lua_init(lua_State *L); -#endif //FTL_LUA_H \ No newline at end of file +#endif //FTL_LUA_H diff --git a/src/procps.h b/src/procps.h index 986d79bb..e707ed6b 100644 --- a/src/procps.h +++ b/src/procps.h @@ -43,4 +43,4 @@ bool read_self_memory_status(struct statm_t *result); bool getProcessMemory(struct proc_mem *mem, const unsigned long total_memory); bool parse_proc_meminfo(struct proc_meminfo *mem); -#endif // PROCPS_H \ No newline at end of file +#endif // PROCPS_H diff --git a/src/resolve.c b/src/resolve.c index b083b0cc..f83c197b 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -66,7 +66,7 @@ struct DNS_HEADER uint16_t auth_count; // number of authority entries uint16_t add_count; // number of resource entries } __attribute__((packed)); -static_assert(sizeof(struct DNS_HEADER) == 12); +static_assert(sizeof(struct DNS_HEADER) == 12, "DNS_HEADER size mismatch"); // Constant sized fields of query structure struct QUESTION @@ -74,7 +74,7 @@ struct QUESTION uint16_t qtype; uint16_t qclass; }; -static_assert(sizeof(struct QUESTION) == 4); +static_assert(sizeof(struct QUESTION) == 4, "QUESTION size mismatch"); // Constant sized fields of the resource record structure struct R_DATA @@ -84,7 +84,7 @@ struct R_DATA uint32_t ttl; // RFC 1035 defines the TTL field as "positive values of a signed 32bit number" uint16_t data_len; } __attribute__((packed)); -static_assert(sizeof(struct R_DATA) == 10); +static_assert(sizeof(struct R_DATA) == 10, "R_DATA size mismatch"); _Pragma("GCC diagnostic pop") // Pointers to resource record contents diff --git a/src/shmem.c b/src/shmem.c index 1d267146..44f72eb8 100644 --- a/src/shmem.c +++ b/src/shmem.c @@ -286,7 +286,7 @@ const char *_getstr(const size_t pos, const char *func, const int line, const ch // Create a mutex for shared memory static void create_mutex(pthread_mutex_t *lock) { log_debug(DEBUG_SHMEM, "Creating SHM mutex lock"); - pthread_mutexattr_t lock_attr = {}; + pthread_mutexattr_t lock_attr; // Initialize the lock attributes pthread_mutexattr_init(&lock_attr); @@ -740,11 +740,15 @@ static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const si // Log output if(resize) + { log_debug(DEBUG_SHMEM, "Resizing \"%s\" from %zu to (%zu * %zu) == %zu (%s)", sharedMemory->name, sharedMemory->size, size1, size2, size, df); + } else + { log_debug(DEBUG_SHMEM, "Remapping \"%s\" from %zu to (%zu * %zu) == %zu", sharedMemory->name, sharedMemory->size, size1, size2, size); + } if(config.misc.check.shmem.v.ui > 0 && percentage > config.misc.check.shmem.v.ui) log_resource_shortage(-1.0, 0, percentage, -1, SHMEM_PATH, df); @@ -801,11 +805,15 @@ static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const si used_shmem += (size - sharedMemory->size); if(sharedMemory->ptr == new_ptr) + { log_debug(DEBUG_SHMEM, "SHMEM pointer not updated: %p (%zu %zu)", sharedMemory->ptr, sharedMemory->size, size); + } else + { log_debug(DEBUG_SHMEM, "SHMEM pointer updated: %p -> %p (%zu %zu)", sharedMemory->ptr, new_ptr, sharedMemory->size, size); + } sharedMemory->ptr = new_ptr; sharedMemory->size = size; diff --git a/src/struct_size.h b/src/struct_size.h index 94c692c7..53bfe12b 100644 --- a/src/struct_size.h +++ b/src/struct_size.h @@ -15,4 +15,4 @@ 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 \ No newline at end of file +#endif // STRUCT_SIZE_HEADER diff --git a/src/syscalls/accept.c b/src/syscalls/accept.c index 710a7f3d..60edbf62 100644 --- a/src/syscalls/accept.c +++ b/src/syscalls/accept.c @@ -39,4 +39,4 @@ int FTLaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, const char errno = _errno; return ret; -} \ No newline at end of file +} diff --git a/src/syscalls/recv.c b/src/syscalls/recv.c index c0e77ecf..bdae2b25 100644 --- a/src/syscalls/recv.c +++ b/src/syscalls/recv.c @@ -41,4 +41,4 @@ ssize_t FTLrecv(int sockfd, void *buf, size_t len, int flags, const char *file, errno = _errno; return ret; -} \ No newline at end of file +} diff --git a/src/syscalls/recvfrom.c b/src/syscalls/recvfrom.c index d40dfadf..b78f8bf5 100644 --- a/src/syscalls/recvfrom.c +++ b/src/syscalls/recvfrom.c @@ -45,4 +45,4 @@ ssize_t FTLrecvfrom(int sockfd, void *buf, size_t len, int flags, struct sockadd errno = _errno; return ret; -} \ No newline at end of file +} diff --git a/src/syscalls/select.c b/src/syscalls/select.c index 5eb07c9a..b6889fb6 100644 --- a/src/syscalls/select.c +++ b/src/syscalls/select.c @@ -41,4 +41,4 @@ int FTLselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st errno = _errno; return ret; -} \ No newline at end of file +} diff --git a/src/syscalls/sendto.c b/src/syscalls/sendto.c index 4e7b4a8e..b0cf0141 100644 --- a/src/syscalls/sendto.c +++ b/src/syscalls/sendto.c @@ -43,4 +43,4 @@ ssize_t FTLsendto(int sockfd, void *buf, size_t len, int flags, const struct soc errno = _errno; return ret; -} \ No newline at end of file +} diff --git a/src/syscalls/strdup.c b/src/syscalls/strdup.c index f83dde47..bd2d7b41 100644 --- a/src/syscalls/strdup.c +++ b/src/syscalls/strdup.c @@ -35,4 +35,4 @@ char* __attribute__((malloc)) FTLstrdup(const char *src, const char *file, const dest[len] = '\0'; return dest; -} \ No newline at end of file +} diff --git a/src/syscalls/syscalls.h b/src/syscalls/syscalls.h index 3d77ebe7..77e7725c 100644 --- a/src/syscalls/syscalls.h +++ b/src/syscalls/syscalls.h @@ -21,17 +21,17 @@ int FTLfallocate(const int fd, const off_t offset, const off_t len, const char * // Interrupt-safe printing routines // printf() is derived from fprintf(stdout, ...) // vprintf() is derived from vfprintf(stdout, ...) -int FTLfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, ...) __attribute__ ((format (gnu_printf, 5, 6))); -int FTLvfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, va_list args) __attribute__ ((format (gnu_printf, 5, 0))); +int FTLfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, ...) __attribute__ ((format (printf, 5, 6))); +int FTLvfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, va_list args) __attribute__ ((format (printf, 5, 0))); -int FTLsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, ...) __attribute__ ((format (gnu_printf, 5, 6))); -int FTLvsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, va_list args) __attribute__ ((format (gnu_printf, 5, 0))); +int FTLsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, ...) __attribute__ ((format (printf, 5, 6))); +int FTLvsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, va_list args) __attribute__ ((format (printf, 5, 0))); -int FTLasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, ...) __attribute__ ((format (gnu_printf, 5, 6))); -int FTLvasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, va_list args) __attribute__ ((format (gnu_printf, 5, 0))); +int FTLasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, ...) __attribute__ ((format (printf, 5, 6))); +int FTLvasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, va_list args) __attribute__ ((format (printf, 5, 0))); -int FTLsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, ...) __attribute__ ((format (gnu_printf, 6, 7))); -int FTLvsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, va_list args) __attribute__ ((format (gnu_printf, 6, 0))); +int FTLsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, ...) __attribute__ ((format (printf, 6, 7))); +int FTLvsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, va_list args) __attribute__ ((format (printf, 6, 0))); // Interrupt-safe socket routines ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const char *func, const int line); diff --git a/src/syscalls/write.c b/src/syscalls/write.c index df62adda..e145007f 100644 --- a/src/syscalls/write.c +++ b/src/syscalls/write.c @@ -50,4 +50,4 @@ ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const // Return number of written bytes return written; -} \ No newline at end of file +} diff --git a/src/tools/arp-scan.c b/src/tools/arp-scan.c index 680a90a3..923625a3 100644 --- a/src/tools/arp-scan.c +++ b/src/tools/arp-scan.c @@ -381,7 +381,7 @@ static void *arp_scan_iface(void *args) thread_data->dst_cidr = netmask_to_cidr(&thread_data->mask.sin_addr); // Get interface index - const int ifindex = if_nametoindex(iface); + const int ifindex = (int)if_nametoindex(iface); // Scan only interfaces with CIDR >= 24 if(thread_data->dst_cidr < 24 && !thread_data->scan_all) @@ -701,7 +701,7 @@ int run_arp_scan(const bool scan_all, const bool extreme_mode) { // Calculate progress (total number of scans / total number of addresses) // We add 1 to total_scans to avoid division by zero - const unsigned int new_progress = 100 * num_scans / (total_scans + 1); + const unsigned int new_progress = 100 * (unsigned int)(num_scans / (total_scans + 1)); if(new_progress > progress) { // Print progress diff --git a/src/tools/dhcp-discover.c b/src/tools/dhcp-discover.c index 85e994b4..c68a74f9 100644 --- a/src/tools/dhcp-discover.c +++ b/src/tools/dhcp-discover.c @@ -54,15 +54,12 @@ // we scan for DHCP activity. #define MAXTHREADS 32 -// Probe DHCP servers responding to the broadcast address -#define PROBE_BCAST - // Should we generate test data for DHCP option 249? //#define TEST_OPT_249 // Global lock used by all threads static pthread_mutex_t lock; -static void __attribute__((format(gnu_printf, 1, 2))) printf_locked(const char *format, ...) +static void __attribute__((format(printf, 1, 2))) printf_locked(const char *format, ...) { va_list args; va_start(args, format); @@ -179,7 +176,7 @@ struct dhcp_packet_data unsigned char chaddr [MAX_DHCP_CHADDR_LENGTH]; // hardware address of this machine char sname [MAX_DHCP_SNAME_LENGTH]; // name of DHCP server char file [MAX_DHCP_FILE_LENGTH]; // boot file name (used for diskless booting?) - char options[MAX_DHCP_OPTIONS_LENGTH]; // options + unsigned char options[MAX_DHCP_OPTIONS_LENGTH]; // options }; // sends a DHCPDISCOVER message to the specified in an attempt to find DHCP servers @@ -219,7 +216,7 @@ static bool send_dhcp_discover(const int sock, const uint32_t xid, const char *i discover_packet.options[6] = 1; // DHCP message type code for DHCPDISCOVER // Place end option at the end of the options - discover_packet.options[7] = 255; + discover_packet.options[7] = (char)255; // Send the DHCPDISCOVER packet to the specified address struct sockaddr_in target = { 0 }; @@ -236,7 +233,7 @@ static bool send_dhcp_discover(const int sock, const uint32_t xid, const char *i printf_locked("DHCDISCOVER giaddr: %s\n", inet_ntoa(discover_packet.giaddr)); #endif // send the DHCPDISCOVER packet - const int bytes = sendto(sock, (char *)&discover_packet, sizeof(discover_packet), 0, (struct sockaddr *)&target, sizeof(target)); + const ssize_t bytes = sendto(sock, (char *)&discover_packet, sizeof(discover_packet), 0, (struct sockaddr *)&target, sizeof(target)); if(bytes < 0) { // strerror() returns "Required key not available" for ENOKEY @@ -250,7 +247,7 @@ static bool send_dhcp_discover(const int sock, const uint32_t xid, const char *i } #ifdef DEBUG - printf_locked("Sent %d bytes\n", bytes); + printf_locked("Sent %zu bytes\n", (size_t)bytes); #endif return true; } @@ -340,7 +337,7 @@ static void print_dhcp_offer(struct in_addr source, struct dhcp_packet_data *off // possible "(empty)" const size_t bufsiz = 4*optlen + 9; char *buffer = calloc(bufsiz, sizeof(char)); - binbuf_to_escaped_C_literal(&offer_packet->options[x], optlen, buffer, bufsiz); + binbuf_to_escaped_C_literal((char*)&offer_packet->options[x], optlen, buffer, bufsiz); printf("%s: \"%s\"\n", opttab[i].name, buffer); free(buffer); } @@ -428,7 +425,7 @@ static void print_dhcp_offer(struct in_addr source, struct dhcp_packet_data *off // chars per control character plus room for // possible "(empty)" char *buffer = calloc(4*optlen + 9, sizeof(char)); - binbuf_to_escaped_C_literal(&offer_packet->options[x], optlen, buffer, sizeof(buffer)); + binbuf_to_escaped_C_literal((char*)&offer_packet->options[x], optlen, buffer, sizeof(buffer)); printf("wpad-server: \"%s\"\n", buffer); free(buffer); } @@ -730,7 +727,7 @@ int run_dhcp_discover(void) pthread_attr_init(&attr); // Create processing/printfing lock - pthread_mutexattr_t lock_attr = {}; + pthread_mutexattr_t lock_attr; // Initialize the lock attributes pthread_mutexattr_init(&lock_attr); // Initialize the lock diff --git a/src/tre-regex/CMakeLists.txt b/src/tre-regex/CMakeLists.txt index f4a8ba96..cdf8ec2e 100644 --- a/src/tre-regex/CMakeLists.txt +++ b/src/tre-regex/CMakeLists.txt @@ -27,4 +27,6 @@ set(sources ) add_library(tre-regex OBJECT ${sources}) -target_compile_options(tre-regex PRIVATE -Wno-maybe-uninitialized -Wno-unused-value -Wno-empty-body) +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + target_compile_options(tre-regex PRIVATE -Wno-maybe-uninitialized -Wno-unused-value -Wno-empty-body) +endif() diff --git a/src/webserver/lua_web.h b/src/webserver/lua_web.h index 478a28a0..5c0b2fe6 100644 --- a/src/webserver/lua_web.h +++ b/src/webserver/lua_web.h @@ -18,4 +18,4 @@ void free_lua(void); void init_lua(const struct mg_connection *conn, void *L, unsigned context_flags); int request_handler(struct mg_connection *conn, void *cbdata); -#endif // LUA_WEB_H \ No newline at end of file +#endif // LUA_WEB_H diff --git a/src/webserver/webserver.c b/src/webserver/webserver.c index 5485046f..ec6c9c7a 100644 --- a/src/webserver/webserver.c +++ b/src/webserver/webserver.c @@ -469,7 +469,8 @@ void http_init(void) } // Configure logging handlers - struct mg_callbacks callbacks = { NULL }; + struct mg_callbacks callbacks; + memset(&callbacks, 0, sizeof(callbacks)); callbacks.log_message = log_http_message; callbacks.log_access = log_http_access; callbacks.init_lua = init_lua; diff --git a/src/webserver/webserver.h b/src/webserver/webserver.h index d87001f4..4fff052a 100644 --- a/src/webserver/webserver.h +++ b/src/webserver/webserver.h @@ -18,4 +18,4 @@ void http_terminate(void); in_port_t get_https_port(void) __attribute__((pure)); unsigned short get_api_string(char **buf, const bool domain); -#endif // WEBSERVER_H \ No newline at end of file +#endif // WEBSERVER_H diff --git a/src/zip/gzip.c b/src/zip/gzip.c index 74aed94c..aa31d86a 100644 --- a/src/zip/gzip.c +++ b/src/zip/gzip.c @@ -92,7 +92,7 @@ static bool deflate_buffer(const unsigned char *buffer_uncompressed, const mz_ul // ITU-T V.42.) // isize: This contains the size of the original (uncompressed) input // data modulo 2^32 (little endian). - const uint32_t crc = mz_crc32(MZ_CRC32_INIT, buffer_uncompressed, size_uncompressed); + const uint32_t crc = (uint32_t)mz_crc32(MZ_CRC32_INIT, buffer_uncompressed, size_uncompressed); memcpy(*buffer_compressed + *size_compressed, &crc, sizeof(crc)); *size_compressed += sizeof(crc); const uint32_t isize = htole32(size_uncompressed); @@ -313,7 +313,15 @@ bool inflate_file(const char *infilename, const char *outfilename, bool verbose) // Get file size fseek(infile, 0, SEEK_END); - const mz_ulong size_compressed = ftell(infile); + const long sc = ftell(infile); + if(sc < 0) + { + log_warn("Failed to get file size of %s", infilename); + fclose(infile); + fclose(outfile); + return false; + } + const mz_ulong size_compressed = (mz_ulong)sc; fseek(infile, 0, SEEK_SET); // Read file into memory @@ -398,7 +406,7 @@ bool deflate_file(const char *infilename, const char *outfilename, bool verbose) // Get file size fseek(infile, 0, SEEK_END); - const mz_ulong size_uncompressed = ftell(infile); + const long size_uncompressed = ftell(infile); fseek(infile, 0, SEEK_SET); // Read file into memory @@ -410,7 +418,7 @@ bool deflate_file(const char *infilename, const char *outfilename, bool verbose) fclose(outfile); return false; } - if(fread(buffer_uncompressed, 1, size_uncompressed, infile) != size_uncompressed) + if(fread(buffer_uncompressed, 1, size_uncompressed, infile) != (size_t)size_uncompressed) { log_warn("Failed to read %lu bytes from %s", (unsigned long)size_uncompressed, infilename); fclose(infile); diff --git a/src/zip/miniz/CMakeLists.txt b/src/zip/miniz/CMakeLists.txt index c6e7de96..40803374 100644 --- a/src/zip/miniz/CMakeLists.txt +++ b/src/zip/miniz/CMakeLists.txt @@ -15,4 +15,5 @@ set(sources add_library(miniz OBJECT ${sources}) target_compile_options(miniz PRIVATE) +target_compile_options(miniz PRIVATE "-Wno-padded") target_include_directories(miniz PRIVATE ${PROJECT_SOURCE_DIR}/src) diff --git a/src/zip/miniz/miniz.h b/src/zip/miniz/miniz.h index d6a354bf..35c740c7 100644 --- a/src/zip/miniz/miniz.h +++ b/src/zip/miniz/miniz.h @@ -1419,4 +1419,4 @@ MINIZ_EXPORT void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filen } #endif -#endif /* MINIZ_NO_ARCHIVE_APIS */ \ No newline at end of file +#endif /* MINIZ_NO_ARCHIVE_APIS */ diff --git a/src/zip/tar.c b/src/zip/tar.c index 5e497622..fa65cd6d 100644 --- a/src/zip/tar.c +++ b/src/zip/tar.c @@ -125,4 +125,4 @@ cJSON * __attribute__((nonnull (1))) list_files_in_tar(const uint8_t *tarData, c } while (p + newOffset + TAR_BLOCK_SIZE <= tarSize); return files; -} \ No newline at end of file +} diff --git a/src/zip/tar.h b/src/zip/tar.h index 11f5e200..a8f30769 100644 --- a/src/zip/tar.h +++ b/src/zip/tar.h @@ -16,4 +16,4 @@ const char *find_file_in_tar(const uint8_t *tar, const size_t tarSize, const char *fileName, size_t *fileSize) __attribute__((nonnull (1,3,4))); cJSON *list_files_in_tar(const uint8_t *tarData, const size_t tarSize) __attribute__((nonnull (1))); -#endif // TAR_H \ No newline at end of file +#endif // TAR_H From f8949103262f85c5c1e046aab513a75737a5c398 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 18 May 2024 10:59:40 +0200 Subject: [PATCH 06/22] Remove explicit static instructions - binaries compiled on alpine will balways e linked statically Signed-off-by: DL6ER --- src/CMakeLists.txt | 3 +-- src/lua/CMakeLists.txt | 2 +- src/lua/ftl_lua.c | 16 ++++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ab5494f..bb2ca546 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -308,9 +308,8 @@ find_library(LIBHISTORY NAMES libhistory${CMAKE_STATIC_LIBRARY_SUFFIX} history) find_library(LIBTERMCAP NAMES libtermcap${CMAKE_STATIC_LIBRARY_SUFFIX} termcap) if(LIBREADLINE AND LIBHISTORY AND LIBTERMCAP) message(STATUS "Building FTL with readline support: YES") - target_compile_definitions(FTL PRIVATE LUA_USE_READLINE) - target_compile_definitions(pihole-FTL PRIVATE LUA_USE_READLINE) target_link_libraries(pihole-FTL ${LIBREADLINE} ${LIBHISTORY} ${LIBTERMCAP}) + add_compile_definitions(HAVE_READLINE) set(HAVE_READLINE TRUE) else() message(STATUS "Building FTL with readline support: NO") diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt index 908b5a7e..79a0305b 100644 --- a/src/lua/CMakeLists.txt +++ b/src/lua/CMakeLists.txt @@ -78,7 +78,7 @@ if(LUA_DL STREQUAL "true") target_compile_definitions(lua PRIVATE LUA_USE_DLOPEN) endif() -if(LIBREADLINE AND LIBHISTORY AND LIBTERMCAP) +if(HAVE_READLINE) message(STATUS "Embedded LUA will use readline for history: YES") target_compile_definitions(lua PRIVATE LUA_USE_READLINE) else() diff --git a/src/lua/ftl_lua.c b/src/lua/ftl_lua.c index 0948ed06..96ce412b 100644 --- a/src/lua/ftl_lua.c +++ b/src/lua/ftl_lua.c @@ -8,20 +8,24 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" #include "ftl_lua.h" + +#include "FTL.h" // struct luaL_Reg #include "lauxlib.h" // get_FTL_version() -#include "../log.h" +#include "log.h" // config struct -#include "../config/config.h" +#include "config/config.h" // file_exists -#include "../files.h" +#include "files.h" // get_web_theme_str -#include "../datastructure.h" +#include "datastructure.h" + #if HAVE_READLINE -#include +# include +# include + #endif #include #include "scripts/scripts.h" From 9fbd40e05fe5e93fce370d1bcba86c5123e12128 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 18 May 2024 11:10:47 +0200 Subject: [PATCH 07/22] Avoid ambigious else Signed-off-by: DL6ER --- src/database/common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/database/common.c b/src/database/common.c index 8d6756c2..f209a50f 100644 --- a/src/database/common.c +++ b/src/database/common.c @@ -253,11 +253,13 @@ void SQLite3LogCallback(void *pArg, int iErrCode, const char *zMsg) if(iErrCode == SQLITE_WARNING) log_warn("SQLite3: %s (%d)", zMsg, iErrCode); else if(iErrCode == SQLITE_NOTICE || iErrCode == SQLITE_SCHEMA) + { // SQLITE_SCHEMA is returned when the database schema has changed // This is not necessarily an error, as sqlite3_step() will re-prepare // the statement and try again. If it cannot, it will return an error // and this will be handled over there. log_debug(DEBUG_ANY, "SQLite3: %s (%d)", zMsg, iErrCode); + } else log_err("SQLite3: %s (%d)", zMsg, iErrCode); } From 313cb2353f1114e5c87540644b75be7e26d8f52b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 18 May 2024 11:39:23 +0200 Subject: [PATCH 08/22] Update C standard to C17 Signed-off-by: DL6ER --- CMakeLists.txt | 6 +++++- src/CMakeLists.txt | 9 +++++---- src/api/theme.c | 2 +- src/config/inotify.c | 2 +- src/database/CMakeLists.txt | 2 +- src/resolve.c | 23 +++++++++++++++++++---- src/tre-regex/tre-config.h | 8 ++++---- src/zip/gzip.c | 6 ++++-- 8 files changed, 40 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5c421ad..67650963 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,11 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -cmake_minimum_required(VERSION 2.8.12) +# C17 supports requires minimum CMake version 3.21 +# GCC 8.1.0 +# LLVM Clang 7.0.0 +cmake_minimum_required(VERSION 3.21) +set(CMAKE_C_STANDARD 17) project(PIHOLE_FTL C) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e3c35bb..878b3971 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,8 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -set(CMAKE_C_STANDARD 11) - # Default to a release with debug info build if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt) if (NOT CMAKE_BUILD_TYPE) @@ -165,13 +163,16 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU") ${EXTRAWARN_GCC12} \ ${EXTRAWARN_GCC13}") elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") - set(EXTRAWARN "-Wnewline-eof \ + set(EXTRAWARN " + -Werror \ + -Wnewline-eof \ -Wno-dangling-else \ -Wno-gnu-zero-variadic-macro-arguments \ -Wno-gnu-variable-sized-type-not-at-end \ -Wno-declaration-after-statement \ -Wno-reserved-identifier \ - -Wno-reserved-macro-identifier") + -Wno-reserved-macro-identifier \ + -Wl,--fatal-warnings") else() message(WARNING "Unknown compiler, not setting warnings flags") set(EXTRAWARN "") diff --git a/src/api/theme.c b/src/api/theme.c index 0b4cf4dc..42529f01 100644 --- a/src/api/theme.c +++ b/src/api/theme.c @@ -11,7 +11,7 @@ // NULL #include // strcasecmp() -#include +#include #include "theme.h" diff --git a/src/config/inotify.c b/src/config/inotify.c index 17767350..dfb3837c 100644 --- a/src/config/inotify.c +++ b/src/config/inotify.c @@ -12,7 +12,7 @@ #include "log.h" #include // NAME_MAX -#include +#include #define WATCHDIR "/etc/pihole" diff --git a/src/database/CMakeLists.txt b/src/database/CMakeLists.txt index b0a4597d..fda25a1a 100644 --- a/src/database/CMakeLists.txt +++ b/src/database/CMakeLists.txt @@ -18,7 +18,7 @@ set(sqlite3_sources ) add_library(sqlite3 OBJECT ${sqlite3_sources}) -target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-sign-compare) +target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-sign-compare -Wno-implicit-function-declaration -Wno-int-conversion) if (CMAKE_C_COMPILER_ID STREQUAL "Clang") target_compile_options(sqlite3 PRIVATE "-Wno-null-pointer-subtraction") diff --git a/src/resolve.c b/src/resolve.c index f83c197b..91b5dce2 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -40,7 +40,7 @@ static unsigned char *name_fromDNS(unsigned char *reader, unsigned char *buffer, // Avoid "error: packed attribute causes inefficient alignment for ..." on ARM32 // builds due to the use of __attribute__((packed)) in the following structs -// Their correct size is ensured for each by static_assert() below +// Their correct size is ensured for each by check_struct_sizes() below _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wattributes\"") @@ -66,7 +66,6 @@ struct DNS_HEADER uint16_t auth_count; // number of authority entries uint16_t add_count; // number of resource entries } __attribute__((packed)); -static_assert(sizeof(struct DNS_HEADER) == 12, "DNS_HEADER size mismatch"); // Constant sized fields of query structure struct QUESTION @@ -74,7 +73,6 @@ struct QUESTION uint16_t qtype; uint16_t qclass; }; -static_assert(sizeof(struct QUESTION) == 4, "QUESTION size mismatch"); // Constant sized fields of the resource record structure struct R_DATA @@ -84,9 +82,18 @@ struct R_DATA uint32_t ttl; // RFC 1035 defines the TTL field as "positive values of a signed 32bit number" uint16_t data_len; } __attribute__((packed)); -static_assert(sizeof(struct R_DATA) == 10, "R_DATA size mismatch"); _Pragma("GCC diagnostic pop") +static bool check_struct_sizes(void) +{ + // Check sizes of structs + assert(sizeof(struct DNS_HEADER) == 12); + assert(sizeof(struct QUESTION) == 4); + assert(sizeof(struct R_DATA) == 10); + + return true; +} + // Pointers to resource record contents struct RES_RECORD { @@ -812,6 +819,14 @@ void *DNSclient_thread(void *val) thread_running[DNSclient] = true; prctl(PR_SET_NAME, thread_names[DNSclient], 0, 0, 0); + // Test struct sizes + if(!check_struct_sizes()) + { + log_err("Struct sizes do not match expected sizes, aborting resolver thread"); + thread_running[DNSclient] = false; + return NULL; + } + // Initial delay until we first try to resolve anything thread_sleepms(DNSclient, 2000); diff --git a/src/tre-regex/tre-config.h b/src/tre-regex/tre-config.h index c93e539c..fdcac795 100644 --- a/src/tre-regex/tre-config.h +++ b/src/tre-regex/tre-config.h @@ -10,17 +10,17 @@ /* #undef C_ALLOCA */ /* Define to 1 if you have `alloca', as a function or macro. */ -#define HAVE_ALLOCA 1 +#define HAVE_ALLOCA 0 /* Define to 1 if you have and it should be used (not on Ultrix). */ -#define HAVE_ALLOCA_H 1 +#define HAVE_ALLOCA_H 0 /* Define if the GNU gettext() function is already present or preinstalled. */ /* #define HAVE_GETTEXT 1 */ /* Define to 1 if you have the `isascii' function. */ -#define HAVE_ISASCII 1 +//#define HAVE_ISASCII 1 /* Define to 1 if you have the `isblank' function. */ #define HAVE_ISBLANK 1 @@ -72,7 +72,7 @@ /* Define if you want TRE to use alloca() instead of malloc() when allocating memory needed for regexec operations. */ -#define TRE_USE_ALLOCA 1 +// #define TRE_USE_ALLOCA 1 /* Define to include the system regex.h from TRE regex.h */ /* #undef TRE_USE_SYSTEM_REGEX_H */ diff --git a/src/zip/gzip.c b/src/zip/gzip.c index aa31d86a..4ec97c74 100644 --- a/src/zip/gzip.c +++ b/src/zip/gzip.c @@ -8,14 +8,16 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ +#include "gzip.h" +#include "log.h" + #include #include #include #include // le32toh and friends +#define __USE_MISC #include -#include "gzip.h" -#include "log.h" static int mz_uncompress2_raw(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len); From d57941790111e789767310102118d6c7636f54b1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 19 May 2024 07:27:06 +0200 Subject: [PATCH 09/22] Ensure target lua_scripts is built before target ftl_lua depending on it Signed-off-by: DL6ER --- src/lua/scripts/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua/scripts/CMakeLists.txt b/src/lua/scripts/CMakeLists.txt index 9afd1afa..0f7aa19d 100644 --- a/src/lua/scripts/CMakeLists.txt +++ b/src/lua/scripts/CMakeLists.txt @@ -27,8 +27,8 @@ foreach(INPUT_FILE ${COMPILED_RESOURCES}) list(APPEND COMPILED_RESOURCES ${OUTPUT_FILE}) endforeach() -# Ensure target lua_scripts is build before target lua -add_dependencies(lua lua_scripts) +# Ensure target lua_scripts is build before target ftl_lua depending on it +add_dependencies(ftl_lua lua_scripts) add_library(lua_scripts OBJECT ${sources}) target_compile_options(lua_scripts PRIVATE ${EXTRAWARN}) From 67fdf2915b04bf45c3888d4b4dff0444e2699f43 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 19 May 2024 08:56:14 +0200 Subject: [PATCH 10/22] Fix conditional for readline inclusion in LUA code Signed-off-by: DL6ER --- src/lua/ftl_lua.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/ftl_lua.c b/src/lua/ftl_lua.c index f649ff10..c5a40066 100644 --- a/src/lua/ftl_lua.c +++ b/src/lua/ftl_lua.c @@ -27,7 +27,7 @@ // prototype for luaopen_pihole() #include "lualib.h" -#if LUA_USE_READLINE +#if defined(LUA_USE_READLINE) # include #endif #include From 25ab7b726c76a9d5151eb2e03a56a85fd3469c19 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 19 May 2024 09:05:44 +0200 Subject: [PATCH 11/22] Print GLIBC version in pihole-FTL -vv and not during compile time as "#pragma message" is not supported by older clang versions Signed-off-by: DL6ER --- src/args.c | 7 ++++++- src/main.c | 6 ------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/args.c b/src/args.c index e4bbd0cd..4333fc4b 100644 --- a/src/args.c +++ b/src/args.c @@ -715,7 +715,12 @@ void parse_args(int argc, char* argv[]) printf("Branch: " GIT_BRANCH "\n"); printf("Commit: " GIT_HASH " (" GIT_DATE ")\n"); printf("Architecture: " FTL_ARCH "\n"); - printf("Compiler: " FTL_CC "\n\n"); + printf("Compiler: " FTL_CC "\n"); +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) + printf("GLIBC version: %d.%d\n\n", __GLIBC__, __GLIBC_MINOR__); +#else + printf("GLIBC version: -\n\n"); +#endif // Print dnsmasq version and compile time options print_dnsmasq_version(yellow, green, bold, normal); diff --git a/src/main.c b/src/main.c index 3d18c74e..61e7b405 100644 --- a/src/main.c +++ b/src/main.c @@ -28,12 +28,6 @@ // export_queries_to_disk() #include "database/query-table.h" -#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) -#pragma message "Minimum GLIBC version: " xstr(__GLIBC__) "." xstr(__GLIBC_MINOR__) -#else -#pragma message "Minimum GLIBC version: unknown, assuming this is a MUSL build" -#endif - char *username; bool needGC = false; bool needDBGC = false; From bfbe309b42373cf69c34046b641e969ec17c89c4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 May 2024 10:24:27 +0200 Subject: [PATCH 12/22] Update build containers to ftl-build v2.5.1 Signed-off-by: DL6ER --- .devcontainer/devcontainer.json | 2 +- .github/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 652e4ece..d58d4db8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,6 @@ { "name": "FTL x86_64 Build Env", - "image": "ghcr.io/pi-hole/ftl-build:v2.5", + "image": "ghcr.io/pi-hole/ftl-build:v2.5.1", "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], "customizations": { "vscode": { diff --git a/.github/Dockerfile b/.github/Dockerfile index 2731b8a2..9ca5a7f3 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/pi-hole/ftl-build:v2.5 AS builder +FROM ghcr.io/pi-hole/ftl-build:v2.5.1 AS builder WORKDIR /app From c957f7820901d67f832f69bc3b387b9ac8bdc8a7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 May 2024 10:31:06 +0200 Subject: [PATCH 13/22] Add Visual Studio Code CMake configuration to get ccompile-time definition detection working Signed-off-by: DL6ER --- .gitignore | 5 ++--- .vscode/c_cpp_properties.json | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.gitignore b/.gitignore index 075dad8f..a3c7c317 100644 --- a/.gitignore +++ b/.gitignore @@ -14,9 +14,8 @@ version~ # IDE files .idea/ *.sw* -/.vscode -.vscode/ -/.vscode/ +.vscode/* +!.vscode/c_cpp_properties.json /build/ # __pycache__ files (API tests) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..901ccbde --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/src/**" + ], + "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file From 8c5da713f8f7e3250deb904b5758b49b6d11c5b2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 May 2024 11:05:15 +0200 Subject: [PATCH 14/22] Add clang build Signed-off-by: DL6ER --- .github/Dockerfile | 4 +++- .github/actions/build-and-test/action.yml | 4 ++++ .github/workflows/build.yml | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/Dockerfile b/.github/Dockerfile index 9ca5a7f3..7dcbabb4 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -10,12 +10,14 @@ ARG GIT_BRANCH="test" ENV GIT_BRANCH ${GIT_BRANCH} ARG GIT_TAG="test" ENV GIT_TAG ${GIT_TAG} +ARG BUILD_OPTS="" +ENV BUILD_OPTS ${BUILD_OPTS} # Build FTL # Remove possible old build files RUN rm -rf cmake && \ # Build FTL - bash build.sh "-DSTATIC=${STATIC}" && \ + bash build.sh "-DSTATIC=${STATIC}" ${BUILD_OPTS} && \ # Run binary architecture tests bash test/arch_test.sh && \ # Run full test suite diff --git a/.github/actions/build-and-test/action.yml b/.github/actions/build-and-test/action.yml index d45fc125..a9c85ea8 100644 --- a/.github/actions/build-and-test/action.yml +++ b/.github/actions/build-and-test/action.yml @@ -5,6 +5,9 @@ inputs: platform: required: true description: The platform to build for + build_opts: + required: true + description: Any extra build opts to use git_branch: required: true description: The branch to build from @@ -76,6 +79,7 @@ runs: "CI_ARCH=${{ inputs.platform }}" "GIT_BRANCH=${{ inputs.git_branch }}" "GIT_TAG=${{ inputs.git_tag }}" + "BUILD_OPTS=${{ inputs.build_opts }}" - name: List files in current directory shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a723888f..370d88ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,10 +64,16 @@ jobs: include: - platform: linux/amd64 bin_name: pihole-FTL-amd64 + build_opts: "" + - platform: linux/amd64 + bin_name: pihole-FTL-amd64-clang + build_opts: clang - platform: linux/386 bin_name: pihole-FTL-386 + build_opts: "" - platform: linux/riscv64 bin_name: pihole-FTL-riscv64 + build_opts: "" env: CI_ARCH: ${{ matrix.platform }} GIT_BRANCH: ${{ needs.smoke-tests.outputs.GIT_BRANCH }} @@ -82,6 +88,7 @@ jobs: with: platform: ${{ matrix.platform }} bin_name: ${{ matrix.bin_name }} + build_opts: ${{ matrix.build_opts }} artifact_name: ${{ matrix.bin_name }}-binary target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} git_branch: ${{ needs.smoke-tests.outputs.GIT_BRANCH }} From 212d0f02a9e09a7c329cfaa09fc3912249c868d0 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 May 2024 11:39:44 +0200 Subject: [PATCH 15/22] Use ftl-build:nightly for devcontainer Signed-off-by: DL6ER --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d58d4db8..bb8c5892 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,6 @@ { "name": "FTL x86_64 Build Env", - "image": "ghcr.io/pi-hole/ftl-build:v2.5.1", + "image": "ghcr.io/pi-hole/ftl-build:nightly", "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], "customizations": { "vscode": { From 4a70b5989c917ffad96bbc81d43e836f7c3ce6bf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 May 2024 20:46:18 +0200 Subject: [PATCH 16/22] Use new-clang ftl-build containers Signed-off-by: DL6ER --- .github/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/Dockerfile b/.github/Dockerfile index 7dcbabb4..141bfc6b 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/pi-hole/ftl-build:v2.5.1 AS builder +FROM ghcr.io/pi-hole/ftl-build:new-clang AS builder WORKDIR /app From 1a72da36169b34a3b7032933c08b699a68ee34cb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 May 2024 22:10:46 +0200 Subject: [PATCH 17/22] Do not build static exectuable in clang test to avoid LTO linking issue Signed-off-by: DL6ER --- build.sh | 1 + src/CMakeLists.txt | 24 +++++++++++++----------- src/dnsmasq/CMakeLists.txt | 2 +- src/zip/miniz/CMakeLists.txt | 3 +-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/build.sh b/build.sh index b92062d1..9809fdd5 100755 --- a/build.sh +++ b/build.sh @@ -65,6 +65,7 @@ done if [[ -n "${clang}" ]]; then export CC=clang export CXX=clang++ + export STATIC="false" fi # Configure build, pass CMake CACHE entries if present diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa12747f..4fb40e3d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -298,22 +298,24 @@ if(STATIC) set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_START_STATIC ON) set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_END_STATIC ON) target_link_libraries(pihole-FTL -static-libgcc -static) + set(LIBRARY_SUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}") else() find_library(LIBMATH m) target_link_libraries(pihole-FTL ${LIBMATH}) + set(LIBRARY_SUFFIX "") endif() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) # for DNSSEC we need the nettle (+ hogweed) crypto and the gmp math libraries -find_library(LIBHOGWEED NAMES libhogweed${CMAKE_STATIC_LIBRARY_SUFFIX} hogweed HINTS /usr/local/lib64) -find_library(LIBGMP NAMES libgmp${CMAKE_STATIC_LIBRARY_SUFFIX} gmp) -find_library(LIBNETTLE NAMES libnettle${CMAKE_STATIC_LIBRARY_SUFFIX} nettle HINTS /usr/local/lib64) +find_library(LIBHOGWEED NAMES libhogweed${LIBRARY_SUFFIX} hogweed HINTS /usr/local/lib64) +find_library(LIBGMP NAMES libgmp${LIBRARY_SUFFIX} gmp) +find_library(LIBNETTLE NAMES libnettle${LIBRARY_SUFFIX} nettle HINTS /usr/local/lib64) # for IDN2 we need the idn2 library which in turn depends on the unistring library -find_library(LIBIDN2 NAMES libidn2${CMAKE_STATIC_LIBRARY_SUFFIX} idn2) -find_library(LIBUNISTRING NAMES libunistring${CMAKE_STATIC_LIBRARY_SUFFIX} unistring) +find_library(LIBIDN2 NAMES libidn2${LIBRARY_SUFFIX} idn2) +find_library(LIBUNISTRING NAMES libunistring${LIBRARY_SUFFIX} unistring) target_link_libraries(pihole-FTL rt Threads::Threads ${LIBHOGWEED} ${LIBGMP} ${LIBNETTLE} ${LIBIDN2} ${LIBUNISTRING}) @@ -334,9 +336,9 @@ add_subdirectory(syscalls) add_subdirectory(config) add_subdirectory(tools) -find_library(LIBREADLINE NAMES libreadline${CMAKE_STATIC_LIBRARY_SUFFIX} readline) -find_library(LIBHISTORY NAMES libhistory${CMAKE_STATIC_LIBRARY_SUFFIX} history) -find_library(LIBTERMCAP NAMES libtermcap${CMAKE_STATIC_LIBRARY_SUFFIX} termcap) +find_library(LIBREADLINE NAMES libreadline${LIBRARY_SUFFIX} readline) +find_library(LIBHISTORY NAMES libhistory${LIBRARY_SUFFIX} history) +find_library(LIBTERMCAP NAMES libtermcap${LIBRARY_SUFFIX} termcap) if(LIBREADLINE AND LIBHISTORY AND LIBTERMCAP) message(STATUS "Building FTL with readline support: YES") target_compile_definitions(lua PRIVATE LUA_USE_READLINE) @@ -350,9 +352,9 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE) endif() -find_library(LIBMBEDCRYPTO NAMES lmbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX} mbedcrypto) -find_library(LIBMBEDX509 NAMES lmbedx509${CMAKE_STATIC_LIBRARY_SUFFIX} mbedx509) -find_library(LIBMBEDTLS NAMES lmbedtls${CMAKE_STATIC_LIBRARY_SUFFIX} mbedtls) +find_library(LIBMBEDCRYPTO NAMES lmbedcrypto${LIBRARY_SUFFIX} mbedcrypto) +find_library(LIBMBEDX509 NAMES lmbedx509${LIBRARY_SUFFIX} mbedx509) +find_library(LIBMBEDTLS NAMES lmbedtls${LIBRARY_SUFFIX} mbedtls) if(LIBMBEDCRYPTO AND LIBMBEDX509 AND LIBMBEDTLS) # Enable TLS support in civetweb if mbedTLS is available message(STATUS "Building FTL with TLS support: YES") diff --git a/src/dnsmasq/CMakeLists.txt b/src/dnsmasq/CMakeLists.txt index 9caab62f..927ed572 100644 --- a/src/dnsmasq/CMakeLists.txt +++ b/src/dnsmasq/CMakeLists.txt @@ -66,7 +66,7 @@ add_library(dnsmasq OBJECT ${sources}) target_compile_definitions(dnsmasq PRIVATE VERSION=\"${DNSMASQ_VERSION}\") target_compile_definitions(dnsmasq PRIVATE CONFFILE=\"/etc/pihole/dnsmasq.conf\") if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized) + target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized -Wno-sign-compare) elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") target_compile_options(dnsmasq PRIVATE -Wno-gnu-variable-sized-type-not-at-end -Wno-sign-compare -Wno-deprecated-non-prototype) endif() diff --git a/src/zip/miniz/CMakeLists.txt b/src/zip/miniz/CMakeLists.txt index 40803374..5047aea3 100644 --- a/src/zip/miniz/CMakeLists.txt +++ b/src/zip/miniz/CMakeLists.txt @@ -14,6 +14,5 @@ set(sources ) add_library(miniz OBJECT ${sources}) -target_compile_options(miniz PRIVATE) -target_compile_options(miniz PRIVATE "-Wno-padded") +target_compile_options(miniz PRIVATE -Wno-padded -Wno-type-limits) target_include_directories(miniz PRIVATE ${PROJECT_SOURCE_DIR}/src) From e10d2a52e1dacd3345b40837c27c9604a5596b6e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 May 2024 19:58:19 +0200 Subject: [PATCH 18/22] Clang-built binaries are expected to be dynamic Signed-off-by: DL6ER --- .devcontainer/devcontainer.json | 2 +- .github/Dockerfile | 8 ++------ build.sh | 3 ++- test/arch_test.sh | 14 ++++++++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index bb8c5892..3fe6ed7f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,6 @@ { "name": "FTL x86_64 Build Env", - "image": "ghcr.io/pi-hole/ftl-build:nightly", + "image": "ghcr.io/pi-hole/ftl-build:new-clang", "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], "customizations": { "vscode": { diff --git a/.github/Dockerfile b/.github/Dockerfile index 141bfc6b..1cbde40e 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -16,12 +16,8 @@ ENV BUILD_OPTS ${BUILD_OPTS} # Build FTL # Remove possible old build files RUN rm -rf cmake && \ -# Build FTL - bash build.sh "-DSTATIC=${STATIC}" ${BUILD_OPTS} && \ -# Run binary architecture tests - bash test/arch_test.sh && \ -# Run full test suite - bash test/run.sh && \ +# Build and test FTL + bash build.sh "-DSTATIC=${STATIC}" test ${BUILD_OPTS} && \ # Move FTL binary to root directory cd / &&\ mv /app/pihole-FTL . && \ diff --git a/build.sh b/build.sh index 9809fdd5..2df0f8f1 100755 --- a/build.sh +++ b/build.sh @@ -96,5 +96,6 @@ fi # If we are asked to run tests, we do this here if [[ -n "${test}" ]]; then cd .. - ./test/run.sh + bash test/arch_test.sh + bash test/run.sh fi diff --git a/test/arch_test.sh b/test/arch_test.sh index 01ca0f4e..ff4bc003 100644 --- a/test/arch_test.sh +++ b/test/arch_test.sh @@ -95,10 +95,16 @@ check_minimum_glibc_version() { if [[ "${CI_ARCH}" == "linux/amd64" ]]; then - check_machine "ELF64" "Advanced Micro Devices X86-64" - check_static # Binary should not rely on any dynamic interpreter - check_libs "" # No dependency on any shared library is intended - check_file "ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped" + if [[ "${STATIC}" == "true" ]]; then + check_machine "ELF64" "Advanced Micro Devices X86-64" + check_static # Binary should not rely on any dynamic interpreter + check_libs "" # No dependency on any shared library is intended + check_file "ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped" +else + check_machine "ELF64" "Advanced Micro Devices X86-64" + check_libs "[libgmp.so.10] [libidn2.so.0] [libc.musl-x86_64.so.1]" + check_file "ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped" + fi elif [[ "${CI_ARCH}" == "linux/386" ]]; then From 62413141ff2bdff2c973ad2ea3be5ea5c9cf5bbb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 May 2024 20:05:07 +0200 Subject: [PATCH 19/22] Only one builder is allowed to push the API documentation Signed-off-by: DL6ER --- .github/actions/build-and-test/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/build-and-test/action.yml b/.github/actions/build-and-test/action.yml index a9c85ea8..8170a570 100644 --- a/.github/actions/build-and-test/action.yml +++ b/.github/actions/build-and-test/action.yml @@ -109,13 +109,13 @@ runs: subject-path: ${{ inputs.bin_name }} - name: Extract documentation files from container - if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64' + if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64' && inputs.build_opts == '' shell: bash run: | tar -xf build.tar api-docs.tar.gz - name: Upload documentation artifacts for deployoment - if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64' + if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64' && inputs.build_opts == '' uses: actions/upload-artifact@v4.3.1 with: name: pihole-api-docs From 782178c6c1ec74f6acea74c93ea6e63d93311e48 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 22 May 2024 20:37:55 +0200 Subject: [PATCH 20/22] Run tests with attached debugger Signed-off-by: DL6ER --- test/run.sh | 8 ++++++++ test/test_suite.bats | 13 ------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/test/run.sh b/test/run.sh index 5f34e9d6..24976551 100755 --- a/test/run.sh +++ b/test/run.sh @@ -73,6 +73,9 @@ export FTLCONF_misc_nice="-11" export FTLCONF_dns_upstrrr="-11" export FTLCONF_debug_api="not_a_bool" +# Prepare gdb session +echo "handle SIGHUP nostop SIGPIPE nostop SIGTERM nostop SIG32 nostop SIG33 nostop SIG34 nostop SIG35 nostop SIG41 nostop" > /root/.gdbinit + # Start FTL if ! su pihole -s /bin/sh -c /home/pihole/pihole-FTL; then echo "pihole-FTL failed to start" @@ -89,6 +92,10 @@ fi # Give FTL some time for startup preparations sleep 2 +# Attach debugger and immediately continue running the binary +# In case a non-ignored signal occurs (a crash), create a full backtrace +gdb -p $(cat /run/pihole-FTL.pid) --ex continue --ex "bt full" & + # Print versions of pihole-FTL echo -n "FTL version (DNS): " dig TXT CHAOS version.FTL @127.0.0.1 +short @@ -130,6 +137,7 @@ if [[ $RET != 0 ]]; then fi # Kill pihole-FTL after having completed tests +# This will also shut down the debugger kill "$(pidof pihole-FTL)" # Restore umask diff --git a/test/test_suite.bats b/test/test_suite.bats index 94c04019..351c85fa 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -972,19 +972,6 @@ [[ "${STATIC}" == "true" && "${lines[@]}" != *"interpreter"* ]] } -@test "Architecture is correctly reported on startup" { - run bash -c 'grep "Compiled for" /var/log/pihole/FTL.log' - printf "Output: %s\n\$CI_ARCH: %s\nuname -m: %s\n" "${lines[@]:-not set}" "${CI_ARCH:-not set}" "$(uname -m)" - [[ ${lines[0]} == *"Compiled for ${CI_ARCH:-$(uname -m)}"* ]] -} - -@test "Building machine (CI) is reported on startup" { - [[ ${CI_ARCH} != "" ]] && compiled_str="on CI" || compiled_str="locally" && export compiled_str - run bash -c 'grep "Compiled for" /var/log/pihole/FTL.log' - printf "Output: %s\n\$CI_ARCH: %s\n" "${lines[@]:-not set}" "${CI_ARCH:-not set}" - [[ ${lines[0]} == *"(compiled ${compiled_str})"* ]] -} - @test "Compiler version is correctly reported on startup" { compiler_version="$(${CC} --version | head -n1)" && export compiler_version run bash -c 'grep "Compiled for" /var/log/pihole/FTL.log' From dc204a41b059f97c8a3e13c36628ee2536cc1a27 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 25 May 2024 09:54:37 +0200 Subject: [PATCH 21/22] Use v2.6 CI containers and nightly for the devcontainer Signed-off-by: DL6ER --- .devcontainer/devcontainer.json | 2 +- .github/Dockerfile | 2 +- ...int-FTL-version-in-interactive-shell.patch | 2 +- src/api/stats_database.c | 10 +++++----- src/config/config.h | 2 +- src/config/legacy_reader.c | 20 ++++++++++--------- src/config/password.c | 2 +- src/database/aliasclients.c | 8 ++++---- src/database/aliasclients.h | 2 +- src/database/gravity-db.c | 14 ++++++------- src/database/network-table.c | 18 ++++++++--------- src/database/query-table.c | 4 ++-- src/database/sqlite3-ext.c | 4 ++-- src/dnsmasq/forward.c | 2 +- src/dnsmasq/helper.c | 2 +- src/dnsmasq/network.c | 4 ++-- src/dnsmasq/option.c | 2 +- src/dnsmasq/rfc1035.c | 2 +- src/syscalls/CMakeLists.txt | 1 + src/syscalls/accept.c | 4 ++-- src/syscalls/asprintf.c | 4 ++-- src/syscalls/calloc.c | 4 ++-- src/syscalls/fopen.c | 4 ++-- src/syscalls/fprintf.c | 4 ++-- src/syscalls/free.c | 4 ++-- src/syscalls/ftlallocate.c | 4 ++-- src/syscalls/pthread_mutex_lock.c | 4 ++-- src/syscalls/realloc.c | 4 ++-- src/syscalls/recv.c | 4 ++-- src/syscalls/recvfrom.c | 4 ++-- src/syscalls/select.c | 4 ++-- src/syscalls/sendto.c | 4 ++-- src/syscalls/snprintf.c | 4 ++-- src/syscalls/sprintf.c | 4 ++-- src/syscalls/strdup.c | 4 ++-- src/syscalls/string.c | 4 ++-- src/syscalls/vasprintf.c | 4 ++-- src/syscalls/vfprintf.c | 4 ++-- src/syscalls/vsnprintf.c | 4 ++-- src/syscalls/vsprintf.c | 4 ++-- src/syscalls/write.c | 4 ++-- 41 files changed, 97 insertions(+), 94 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3fe6ed7f..bb8c5892 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,6 @@ { "name": "FTL x86_64 Build Env", - "image": "ghcr.io/pi-hole/ftl-build:new-clang", + "image": "ghcr.io/pi-hole/ftl-build:nightly", "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], "customizations": { "vscode": { diff --git a/.github/Dockerfile b/.github/Dockerfile index 1cbde40e..046e45f6 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/pi-hole/ftl-build:new-clang AS builder +FROM ghcr.io/pi-hole/ftl-build:v2.6 AS builder WORKDIR /app diff --git a/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch b/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch index 1efac968..c7aaa292 100644 --- a/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch +++ b/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch @@ -7,7 +7,7 @@ index 6280ebf6..a5e82f70 100644 #include #include +// print_FTL_version() -+#include "../log.h" ++#include "log.h" #if !defined(_WIN32) && !defined(WIN32) # include diff --git a/src/api/stats_database.c b/src/api/stats_database.c index 5a30b105..61213c1e 100644 --- a/src/api/stats_database.c +++ b/src/api/stats_database.c @@ -8,16 +8,16 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" -#include "../webserver/http-common.h" -#include "../webserver/json_macros.h" +#include "FTL.h" +#include "webserver/http-common.h" +#include "webserver/json_macros.h" #include "api.h" // querytypes[] -#include "../datastructure.h" +#include "datastructure.h" // logging routines #include "log.h" // db -#include "../database/common.h" +#include "database/common.h" // SQL Query type filters for the database #define FILTER_STATUS_NOT_BLOCKED "status IN (0,2,3,12,13,14,17)" diff --git a/src/config/config.h b/src/config/config.h index 6cd4f05e..013414ed 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -11,7 +11,7 @@ #define CONFIG_H // enum privacy_level -#include "../enums.h" +#include "enums.h" #include // typedef int16_t #include diff --git a/src/config/legacy_reader.c b/src/config/legacy_reader.c index 06173fea..75e9118a 100644 --- a/src/config/legacy_reader.c +++ b/src/config/legacy_reader.c @@ -28,7 +28,7 @@ static pthread_mutex_t lock; // Private prototypes static char *parseFTLconf(FILE *fp, const char *key); static void releaseConfigMemory(void); -static char *getPath(FILE* fp, const char *option, char *ptr); +static char *__attribute__((nonnull(1,2,3), malloc, warn_unused_result)) getPath(FILE* fp, const char *option, char *ptr); static bool parseBool(const char *option, bool *ptr); static void readDebugingSettingsLegacy(FILE *fp); static void getBlockingModeLegacy(FILE *fp); @@ -593,7 +593,7 @@ const char *readFTLlegacy(struct config *conf) return path; } -static char *getPath(FILE* fp, const char *option, char *path_default) +static char *__attribute__((nonnull(1,2,3), malloc, warn_unused_result)) getPath(FILE* fp, const char *option, char *path_default) { // This subroutine is used to read paths from pihole-FTL.conf // fp: File path to opened and readable config file @@ -604,22 +604,24 @@ static char *getPath(FILE* fp, const char *option, char *path_default) errno = 0; // Use sscanf() to obtain filename from config file parameter only if buffer != NULL char *val_ptr = calloc(128, sizeof(char)); - if(buffer == NULL || sscanf(buffer, "%127s", val_ptr) != 1) - { - // Use standard path if no custom path was obtained from the config file - return path_default; - } // Test if memory allocation was successful if(val_ptr == NULL) { - log_crit("Allocating memory for %s failed (%s, %i). Exiting.", option, strerror(errno), errno); + log_crit("Allocating memory for %s failed (%s, %i). Exiting.", + option, strerror(errno), errno); exit(EXIT_FAILURE); } - else if(strlen(val_ptr) == 0) + + if(buffer == NULL || sscanf(buffer, "%127s", val_ptr) != 1 || strlen(val_ptr) == 0) { + // Use standard path if no custom path was obtained from the config file log_info(" %s: Empty path is not possible, using default", option); + + strncpy(val_ptr, path_default, 127); + val_ptr[127] = '\0'; + return val_ptr; } return val_ptr; diff --git a/src/config/password.c b/src/config/password.c index c1231ed7..5c32411c 100644 --- a/src/config/password.c +++ b/src/config/password.c @@ -315,7 +315,7 @@ char * __attribute__((malloc)) create_password(const char *password) enum password_result verify_login(const char *password) { enum password_result pw = verify_password(password, config.webserver.api.pwhash.v.s, true); - log_debug(DEBUG_API, pw == PASSWORD_CORRECT ? "Password correct" : "Password incorrect"); + log_debug(DEBUG_API, "Password %s correct", pw == PASSWORD_CORRECT ? "" : "not"); // Check if an application password is set and if it matches if(pw == PASSWORD_INCORRECT && diff --git a/src/database/aliasclients.c b/src/database/aliasclients.c index f060e217..7e8fddeb 100644 --- a/src/database/aliasclients.c +++ b/src/database/aliasclients.c @@ -8,15 +8,15 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" #include "aliasclients.h" #include "common.h" // global counters variable -#include "../shmem.h" +#include "shmem.h" // global config variable -#include "../config/config.h" +#include "config/config.h" // logging routines -#include "../log.h" +#include "log.h" // getAliasclientIDfromIP() #include "network-table.h" diff --git a/src/database/aliasclients.h b/src/database/aliasclients.h index 8eb6d2f7..a03617fc 100644 --- a/src/database/aliasclients.h +++ b/src/database/aliasclients.h @@ -11,7 +11,7 @@ #define ALIASCLIENTS_TABLE_H // type clientsData -#include "../datastructure.h" +#include "datastructure.h" bool create_aliasclients_table(sqlite3 *db); diff --git a/src/database/gravity-db.c b/src/database/gravity-db.c index fef07869..d922e2d7 100644 --- a/src/database/gravity-db.c +++ b/src/database/gravity-db.c @@ -8,29 +8,29 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" #include "sqlite3.h" #include "gravity-db.h" // struct config -#include "../config/config.h" +#include "config/config.h" // logging routines -#include "../log.h" +#include "log.h" // getstr() -#include "../shmem.h" +#include "shmem.h" // SQLite3 prepared statement vectors -#include "../vector.h" +#include "vector.h" // log_subnet_warning() // logg_inaccessible_adlist #include "message-table.h" // getMACfromIP() #include "network-table.h" // struct DNSCacheData -#include "../datastructure.h" +#include "datastructure.h" // reset_aliasclient() #include "aliasclients.h" // Definition of struct regexData -#include "../regex_r.h" +#include "regex_r.h" // Prefix of interface names in the client table #define INTERFACE_SEP ":" diff --git a/src/database/network-table.c b/src/database/network-table.c index 1e2a8817..2899d4aa 100644 --- a/src/database/network-table.c +++ b/src/database/network-table.c @@ -8,21 +8,21 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" #include "network-table.h" #include "common.h" -#include "../shmem.h" -#include "../log.h" +#include "shmem.h" +#include "log.h" // timer_elapsed_msec() -#include "../timers.h" -#include "../config/config.h" -#include "../datastructure.h" +#include "timers.h" +#include "config/config.h" +#include "datastructure.h" // struct config -#include "../config/config.h" +#include "config/config.h" // resolve_this_name() -#include "../resolve.h" +#include "resolve.h" // killed -#include "../signals.h" +#include "signals.h" // Private prototypes static char *getMACVendor(const char *hwaddr) __attribute__ ((malloc)); diff --git a/src/database/query-table.c b/src/database/query-table.c index bcce7dfc..342730a4 100644 --- a/src/database/query-table.c +++ b/src/database/query-table.c @@ -1120,13 +1120,13 @@ void DB_read_queries(void) (buffer = (const char *)sqlite3_column_text(stmt, 6)) != NULL) { // Get IP address and port of upstream destination - char serv_addr[INET6_ADDRSTRLEN + 1] = { 0 }; + char serv_addr[INET6_ADDRSTRLEN + 16] = { 0 }; unsigned int serv_port = 53; // We limit the number of bytes written into the serv_addr buffer // to prevent buffer overflows. If there is no port available in // the database, we skip extracting them and use the default port sscanf(buffer, "%"xstr(INET6_ADDRSTRLEN)"[^#]#%u", serv_addr, &serv_port); - serv_addr[INET6_ADDRSTRLEN-1] = '\0'; + serv_addr[INET6_ADDRSTRLEN + 15] = '\0'; upstreamID = findUpstreamID(serv_addr, (in_port_t)serv_port); } diff --git a/src/database/sqlite3-ext.c b/src/database/sqlite3-ext.c index e3e28498..b065576e 100644 --- a/src/database/sqlite3-ext.c +++ b/src/database/sqlite3-ext.c @@ -22,9 +22,9 @@ // free() #include // logging routines -#include "../log.h" +#include "log.h" // struct config -#include "../config/config.h" +#include "config/config.h" // isMAC() #include "network-table.h" diff --git a/src/dnsmasq/forward.c b/src/dnsmasq/forward.c index f9316a08..15713ec2 100644 --- a/src/dnsmasq/forward.c +++ b/src/dnsmasq/forward.c @@ -15,7 +15,7 @@ */ #include "dnsmasq.h" -#include "../dnsmasq_interface.h" +#include "dnsmasq_interface.h" static struct frec *get_new_frec(time_t now, struct server *serv, int force); static struct frec *lookup_frec(unsigned short id, int fd, void *hash, int *firstp, int *lastp); diff --git a/src/dnsmasq/helper.c b/src/dnsmasq/helper.c index a59a0a78..65727ba4 100644 --- a/src/dnsmasq/helper.c +++ b/src/dnsmasq/helper.c @@ -15,7 +15,7 @@ */ #include "dnsmasq.h" -#include "../log.h" +#include "log.h" #ifdef HAVE_SCRIPT diff --git a/src/dnsmasq/network.c b/src/dnsmasq/network.c index 60799d48..9e009f77 100644 --- a/src/dnsmasq/network.c +++ b/src/dnsmasq/network.c @@ -15,8 +15,8 @@ */ #include "dnsmasq.h" -#include "../dnsmasq_interface.h" -#include "../log.h" +#include "dnsmasq_interface.h" +#include "log.h" #ifdef HAVE_LINUX_NETWORK diff --git a/src/dnsmasq/option.c b/src/dnsmasq/option.c index 249a6f35..8e7377dc 100644 --- a/src/dnsmasq/option.c +++ b/src/dnsmasq/option.c @@ -20,7 +20,7 @@ #include /* Pi-hole modification */ -#include "../log.h" +#include "log.h" /************************/ static volatile int mem_recover = 0; diff --git a/src/dnsmasq/rfc1035.c b/src/dnsmasq/rfc1035.c index 06d3067c..ef618ff0 100644 --- a/src/dnsmasq/rfc1035.c +++ b/src/dnsmasq/rfc1035.c @@ -15,7 +15,7 @@ */ #include "dnsmasq.h" -#include "../dnsmasq_interface.h" +#include "dnsmasq_interface.h" int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, char *name, int isExtract, int extrabytes) diff --git a/src/syscalls/CMakeLists.txt b/src/syscalls/CMakeLists.txt index 10103094..7ba43aa4 100644 --- a/src/syscalls/CMakeLists.txt +++ b/src/syscalls/CMakeLists.txt @@ -36,3 +36,4 @@ set(sources add_library(syscalls OBJECT ${sources}) target_compile_options(syscalls PRIVATE ${EXTRAWARN}) +target_include_directories(syscalls PRIVATE ${PROJECT_SOURCE_DIR}/src) diff --git a/src/syscalls/accept.c b/src/syscalls/accept.c index 60edbf62..ef53bad2 100644 --- a/src/syscalls/accept.c +++ b/src/syscalls/accept.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef accept int FTLaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, const char *file, const char *func, const int line) diff --git a/src/syscalls/asprintf.c b/src/syscalls/asprintf.c index 4da1ea82..67585bb0 100644 --- a/src/syscalls/asprintf.c +++ b/src/syscalls/asprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" int FTLasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, ...) { diff --git a/src/syscalls/calloc.c b/src/syscalls/calloc.c index 60c2d2f0..e8de9821 100644 --- a/src/syscalls/calloc.c +++ b/src/syscalls/calloc.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef calloc void* __attribute__((malloc)) __attribute__((alloc_size(1,2))) FTLcalloc(const size_t nmemb, const size_t size, const char *file, const char *func, const int line) diff --git a/src/syscalls/fopen.c b/src/syscalls/fopen.c index 71912a69..9dd603a4 100644 --- a/src/syscalls/fopen.c +++ b/src/syscalls/fopen.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" static uint8_t already_writing = 0; diff --git a/src/syscalls/fprintf.c b/src/syscalls/fprintf.c index be3bee68..d64d85ab 100644 --- a/src/syscalls/fprintf.c +++ b/src/syscalls/fprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" int FTLfprintf(FILE *stream, const char *file, const char *func, const int line, const char *format, ...) { diff --git a/src/syscalls/free.c b/src/syscalls/free.c index 1091aa14..360170ea 100644 --- a/src/syscalls/free.c +++ b/src/syscalls/free.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef free void FTLfree(void **ptr, const char *file, const char *func, const int line) diff --git a/src/syscalls/ftlallocate.c b/src/syscalls/ftlallocate.c index 8140f1b8..b1330ae7 100644 --- a/src/syscalls/ftlallocate.c +++ b/src/syscalls/ftlallocate.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #include // off_t is automatically set as off64_t when this is a 64bit system diff --git a/src/syscalls/pthread_mutex_lock.c b/src/syscalls/pthread_mutex_lock.c index ab4b0112..1fc1821a 100644 --- a/src/syscalls/pthread_mutex_lock.c +++ b/src/syscalls/pthread_mutex_lock.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #include diff --git a/src/syscalls/realloc.c b/src/syscalls/realloc.c index 77f83f4a..aa2b12a3 100644 --- a/src/syscalls/realloc.c +++ b/src/syscalls/realloc.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef realloc void __attribute__((alloc_size(2))) *FTLrealloc(void *ptr_in, const size_t size, const char * file, const char * func, const int line) diff --git a/src/syscalls/recv.c b/src/syscalls/recv.c index bdae2b25..0dce546d 100644 --- a/src/syscalls/recv.c +++ b/src/syscalls/recv.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #include diff --git a/src/syscalls/recvfrom.c b/src/syscalls/recvfrom.c index b78f8bf5..b703ad04 100644 --- a/src/syscalls/recvfrom.c +++ b/src/syscalls/recvfrom.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #include #include diff --git a/src/syscalls/select.c b/src/syscalls/select.c index b6889fb6..1907ba51 100644 --- a/src/syscalls/select.c +++ b/src/syscalls/select.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #include diff --git a/src/syscalls/sendto.c b/src/syscalls/sendto.c index b0cf0141..c3d0710b 100644 --- a/src/syscalls/sendto.c +++ b/src/syscalls/sendto.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #include #include diff --git a/src/syscalls/snprintf.c b/src/syscalls/snprintf.c index 699d942c..7384eec4 100644 --- a/src/syscalls/snprintf.c +++ b/src/syscalls/snprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" int FTLsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, ...) { diff --git a/src/syscalls/sprintf.c b/src/syscalls/sprintf.c index a6cc4094..c3ef0563 100644 --- a/src/syscalls/sprintf.c +++ b/src/syscalls/sprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" int FTLsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, ...) { diff --git a/src/syscalls/strdup.c b/src/syscalls/strdup.c index bd2d7b41..dc912f5d 100644 --- a/src/syscalls/strdup.c +++ b/src/syscalls/strdup.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" char* __attribute__((malloc)) FTLstrdup(const char *src, const char *file, const char *func, const int line) { diff --git a/src/syscalls/string.c b/src/syscalls/string.c index 88254e35..1d394252 100644 --- a/src/syscalls/string.c +++ b/src/syscalls/string.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef strlen size_t FTLstrlen(const char *s, const char *file, const char *func, const int line) diff --git a/src/syscalls/vasprintf.c b/src/syscalls/vasprintf.c index 3ac340e6..d1a268e9 100644 --- a/src/syscalls/vasprintf.c +++ b/src/syscalls/vasprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef vasprintf int FTLvasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, va_list args) diff --git a/src/syscalls/vfprintf.c b/src/syscalls/vfprintf.c index c7a82de6..516271dc 100644 --- a/src/syscalls/vfprintf.c +++ b/src/syscalls/vfprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" // itoa implementation using only static memory // taken from Kernighan and Ritchie's "The C Programming Language" diff --git a/src/syscalls/vsnprintf.c b/src/syscalls/vsnprintf.c index 4f4badfc..690d90f0 100644 --- a/src/syscalls/vsnprintf.c +++ b/src/syscalls/vsnprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef vsnprintf int FTLvsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, va_list args) diff --git a/src/syscalls/vsprintf.c b/src/syscalls/vsprintf.c index cce0b35f..72aee733 100644 --- a/src/syscalls/vsprintf.c +++ b/src/syscalls/vsprintf.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef vsprintf int FTLvsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, va_list args) diff --git a/src/syscalls/write.c b/src/syscalls/write.c index e145007f..bdb8eafc 100644 --- a/src/syscalls/write.c +++ b/src/syscalls/write.c @@ -8,9 +8,9 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -#include "../FTL.h" +#include "FTL.h" //#include "syscalls.h" is implicitly done in FTL.h -#include "../log.h" +#include "log.h" #undef write ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const char *func, const int line) From 40eee1ac9c7c3663fa994ebc316deec791a83740 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 25 May 2024 09:57:46 +0200 Subject: [PATCH 22/22] Addres spellchecker complaints Signed-off-by: DL6ER --- .github/.codespellignore_lines | 2 ++ src/config/toml_helper.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/.codespellignore_lines b/.github/.codespellignore_lines index 49f7eebf..a592a395 100644 --- a/.github/.codespellignore_lines +++ b/.github/.codespellignore_lines @@ -1 +1,3 @@ self.errors.append("Exception when GETing from FTL: " + str(e)) +// sitten -> sittin (substitution of "i" for "e"), +// sittin -> sitting (insertion of "g" at the end). diff --git a/src/config/toml_helper.c b/src/config/toml_helper.c index 04ade29b..26c6b1dd 100644 --- a/src/config/toml_helper.c +++ b/src/config/toml_helper.c @@ -209,7 +209,7 @@ void print_comment(FILE *fp, const char *str, const char *intro, const unsigned // If this the first line? If not, add a newline if (i > 0) fputc('\n', fp); - // Add intendation + // Add indentation for (unsigned int j = 0; j != 2*indent; ++j) fputc(' ', fp); // Start a new line @@ -428,7 +428,7 @@ void writeTOMLvalue(FILE * fp, const int indent, const enum conf_type t, union c if(strlen(item->valuestring) == 0) continue; - // Add intendation (if we are indenting) + // Add indentation (if we are indenting) if(indent > -1) indentTOML(fp, indent + 1);