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 <dl6er@dl6er.de>
This commit is contained in:
parent
bccfa2245f
commit
32de390b00
7
build.sh
7
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
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -60,4 +60,4 @@ struct session {
|
|||
char csrf[SID_SIZE];
|
||||
};
|
||||
|
||||
#endif // AUTH_H
|
||||
#endif // AUTH_H
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
#endif //CONFIG_CLI_H
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 &&
|
||||
|
|
|
@ -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 "<cname>,[<cnameX>,]<target>[,<TTL>]"
|
||||
// <cnameX> 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 "<enabled>,<ip-address>[/<prefix-len>],<server>[#<port>],<domain>"
|
||||
// Mandatory elements are: <enabled>, <ip-address>, <server>, and <domain>
|
||||
// Optional elements are: [/<prefix-len>] and [#<port>]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -215,4 +215,4 @@ int sqlite3_pihole_extensions_init(sqlite3 *db, const char **pzErrMsg, const str
|
|||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -419,4 +419,4 @@ void FTL_parse_pseudoheaders(unsigned char *pheader, const size_t plen)
|
|||
p += optlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ enum domain_client_status {
|
|||
} __attribute__ ((packed));
|
||||
|
||||
enum debug_flag {
|
||||
DEBUG_NONE = 0,
|
||||
DEBUG_DATABASE = 1,
|
||||
DEBUG_NETWORKING,
|
||||
DEBUG_LOCKS,
|
||||
|
|
|
@ -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
|
||||
#endif // EVENTS_H
|
||||
|
|
|
@ -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))
|
||||
|
|
17
src/log.h
17
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
#include "../files.h"
|
||||
// get_web_theme_str
|
||||
#include "../datastructure.h"
|
||||
#if HAVE_READLINE
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
#include <wordexp.h>
|
||||
#include "scripts/scripts.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
|
||||
#endif //FTL_LUA_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
|
||||
#endif // PROCPS_H
|
||||
|
|
|
@ -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
|
||||
|
|
10
src/shmem.c
10
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;
|
||||
|
|
|
@ -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
|
||||
#endif // STRUCT_SIZE_HEADER
|
||||
|
|
|
@ -39,4 +39,4 @@ int FTLaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, const char
|
|||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,4 +41,4 @@ ssize_t FTLrecv(int sockfd, void *buf, size_t len, int flags, const char *file,
|
|||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,4 +45,4 @@ ssize_t FTLrecvfrom(int sockfd, void *buf, size_t len, int flags, struct sockadd
|
|||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,4 +41,4 @@ int FTLselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
|
|||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,4 +43,4 @@ ssize_t FTLsendto(int sockfd, void *buf, size_t len, int flags, const struct soc
|
|||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,4 @@ char* __attribute__((malloc)) FTLstrdup(const char *src, const char *file, const
|
|||
dest[len] = '\0';
|
||||
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
#endif // LUA_WEB_H
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
#endif // WEBSERVER_H
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 */
|
||||
#endif /* MINIZ_NO_ARCHIVE_APIS */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
#endif // TAR_H
|
||||
|
|
Loading…
Reference in New Issue