From ee4a6d0e49ffab1d2662775a5f65ab555bfd7253 Mon Sep 17 00:00:00 2001 From: Federico Aponte Date: Mon, 4 Dec 2023 23:19:40 +0100 Subject: [PATCH] build: fix some more Clang warnings Signed-off-by: Federico Aponte --- cmake/modules/CompilerFlags.cmake | 7 ++++ driver/dynamic_params_table.c | 18 ++++----- driver/event_table.c | 37 ++++++++++--------- driver/fillers_table.c | 3 ++ test/libscap/helpers/engines.cpp | 2 +- userspace/libscap/linux/scap_cgroup.c | 2 +- userspace/libsinsp/test/container_info.ut.cpp | 3 ++ userspace/libsinsp/utils.cpp | 4 +- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/cmake/modules/CompilerFlags.cmake b/cmake/modules/CompilerFlags.cmake index 643b750e9f..67cc75cc04 100644 --- a/cmake/modules/CompilerFlags.cmake +++ b/cmake/modules/CompilerFlags.cmake @@ -42,6 +42,13 @@ if(NOT MSVC) if(BUILD_WARNINGS_AS_ERRORS) set(CMAKE_COMPILE_WARNING_AS_ERROR ON) set(CMAKE_SUPPRESSED_WARNINGS "-Wno-unused-parameter -Wno-sign-compare -Wno-implicit-fallthrough -Wno-format-truncation") + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + # Clang needs these for suppressing these warnings: + # - C++20 array designators used with C++17 + # - C99 array designators used in C++ + # - avoid complaining about the option above `-Wno-format-truncation` + set(CMAKE_SUPPRESSED_WARNINGS "${CMAKE_SUPPRESSED_WARNINGS} -Wno-c++20-designator -Wno-c99-designator -Wno-unknown-warning-option") + endif() set(FALCOSECURITY_LIBS_COMMON_FLAGS "${FALCOSECURITY_LIBS_COMMON_FLAGS} -Wextra ${CMAKE_SUPPRESSED_WARNINGS}") endif() diff --git a/driver/dynamic_params_table.c b/driver/dynamic_params_table.c index 295e71c221..91b7da7f3b 100644 --- a/driver/dynamic_params_table.c +++ b/driver/dynamic_params_table.c @@ -11,19 +11,19 @@ or GPL2.txt for full copies of the license. #include "ppm_events_public.h" const struct ppm_param_info sockopt_dynamic_param[PPM_SOCKOPT_IDX_MAX] = { - [PPM_SOCKOPT_IDX_UNKNOWN] = {{0}, PT_BYTEBUF, PF_HEX}, - [PPM_SOCKOPT_IDX_ERRNO] = {{0}, PT_ERRNO, PF_DEC}, - [PPM_SOCKOPT_IDX_UINT32] = {{0}, PT_UINT32, PF_DEC}, - [PPM_SOCKOPT_IDX_UINT64] = {{0}, PT_UINT64, PF_DEC}, - [PPM_SOCKOPT_IDX_TIMEVAL] = {{0}, PT_RELTIME, PF_DEC}, + [PPM_SOCKOPT_IDX_UNKNOWN] = {{0}, PT_BYTEBUF, PF_HEX, 0, 0}, + [PPM_SOCKOPT_IDX_ERRNO] = {{0}, PT_ERRNO, PF_DEC, 0, 0}, + [PPM_SOCKOPT_IDX_UINT32] = {{0}, PT_UINT32, PF_DEC, 0, 0}, + [PPM_SOCKOPT_IDX_UINT64] = {{0}, PT_UINT64, PF_DEC, 0, 0}, + [PPM_SOCKOPT_IDX_TIMEVAL] = {{0}, PT_RELTIME, PF_DEC, 0, 0}, }; const struct ppm_param_info ptrace_dynamic_param[PPM_PTRACE_IDX_MAX] = { - [PPM_PTRACE_IDX_UINT64] = {{0}, PT_UINT64, PF_HEX}, - [PPM_PTRACE_IDX_SIGTYPE] = {{0}, PT_SIGTYPE, PF_DEC}, + [PPM_PTRACE_IDX_UINT64] = {{0}, PT_UINT64, PF_HEX, 0, 0}, + [PPM_PTRACE_IDX_SIGTYPE] = {{0}, PT_SIGTYPE, PF_DEC, 0, 0}, }; const struct ppm_param_info bpf_dynamic_param[PPM_BPF_IDX_MAX] = { - [PPM_BPF_IDX_FD] = {{0}, PT_FD, PF_DEC}, - [PPM_BPF_IDX_RES] = {{0}, PT_ERRNO, PF_DEC}, + [PPM_BPF_IDX_FD] = {{0}, PT_FD, PF_DEC, 0, 0}, + [PPM_BPF_IDX_RES] = {{0}, PT_ERRNO, PF_DEC, 0, 0}, }; diff --git a/driver/event_table.c b/driver/event_table.c index 6d6e23fd2e..f1ef41f9f2 100644 --- a/driver/event_table.c +++ b/driver/event_table.c @@ -12,41 +12,43 @@ or GPL2.txt for full copies of the license. * - Enter and exit events should have the same flags unless the exit one is `EC_UNKNOWN`. * * - The `ppm_event_category` is composed of 2 parts: - * + * * 1. The highest bits represent the event category: * - `EC_SYSCALL` * - `EC_TRACEPOINT * - `EC_PLUGIN` * - `EC_METAEVENT` - * + * * 2. The lowest bits represent the syscall category to which the specific event belongs. - * - * All events must have only one syscall category and one event category. Exception: events + * + * All events must have only one syscall category and one event category. Exception: events * marked with `EC_UNKNOWN` flag must only have the syscall category equal to `EC_UNKNOWN`. - * + * * - All events that are no more sent by our drivers must have the `EF_OLD_VERSION` flag. - * + * * - Events marked with `EC_UNKNOWN` must have a name equal to `NA`. - * + * * - All events that have the "EF_USES_FD" flag should return as first parameter a file descriptor. - * "libsinsp" will try to access the first parameter and use it as a file descriptor. If the event has - * 0 parameters but has the "EF_USES_FD" flag then a runtime error will occur shutting down the process. - * Furthermore if an exit event has the "EF_USES_FD" then also the related enter event must have - * it (following the logic described above). Otherwise the exit event will not trigger "libsinsp" code + * "libsinsp" will try to access the first parameter and use it as a file descriptor. If the event has + * 0 parameters but has the "EF_USES_FD" flag then a runtime error will occur shutting down the process. + * Furthermore if an exit event has the "EF_USES_FD" then also the related enter event must have + * it (following the logic described above). Otherwise the exit event will not trigger "libsinsp" code * in order to properly manage the file descriptor returned by the exit event. - * + * * - The only kind of change permitted for pre-existent events is adding parameters. If you need to modify or * remove some existing parameters you must create a new event pair. The new enum name should be equal to the previous one * but with the version bumped by 1. - * Consider the `PPME_SYSCALL_EXECVE_19_E` event as an example, if you want to create a new version for it, the new enum - * will be called `PPME_SYSCALL_EXECVE_20_E`. - * - * - All the versions of the same event must have the same name + * Consider the `PPME_SYSCALL_EXECVE_19_E` event as an example, if you want to create a new version for it, the new enum + * will be called `PPME_SYSCALL_EXECVE_20_E`. + * + * - All the versions of the same event must have the same name */ #include "ppm_events_public.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" const struct ppm_event_info g_event_info[] = { [PPME_GENERIC_E] = {"syscall", EC_OTHER | EC_SYSCALL, EF_NONE, 2, {{"ID", PT_SYSCALLID, PF_DEC}, {"nativeID", PT_UINT16, PF_DEC} } }, [PPME_GENERIC_X] = {"syscall", EC_OTHER | EC_SYSCALL, EF_NONE, 1, {{"ID", PT_SYSCALLID, PF_DEC} } }, @@ -459,7 +461,7 @@ const struct ppm_event_info g_event_info[] = { [PPME_SYSCALL_PIDFD_GETFD_E] = {"pidfd_getfd", EC_PROCESS | EC_SYSCALL, EF_CREATES_FD | EF_MODIFIES_STATE, 0}, [PPME_SYSCALL_PIDFD_GETFD_X] = {"pidfd_getfd", EC_PROCESS | EC_SYSCALL, EF_CREATES_FD | EF_MODIFIES_STATE, 4, {{"fd", PT_FD, PF_DEC}, {"pid_fd", PT_FD, PF_DEC}, {"target_fd", PT_FD, PF_DEC}, {"flags", PT_FLAGS32, PF_HEX}}}, [PPME_SYSCALL_PIDFD_OPEN_E] = {"pidfd_open", EC_PROCESS | EC_SYSCALL, EF_CREATES_FD | EF_MODIFIES_STATE, 0}, - [PPME_SYSCALL_PIDFD_OPEN_X] = {"pidfd_open", EC_PROCESS | EC_SYSCALL, EF_CREATES_FD | EF_MODIFIES_STATE, 3, {{"fd", PT_FD, PF_DEC}, {"pid", PT_PID, PF_DEC}, {"flags", PT_FLAGS32, PF_HEX}}}, + [PPME_SYSCALL_PIDFD_OPEN_X] = {"pidfd_open", EC_PROCESS | EC_SYSCALL, EF_CREATES_FD | EF_MODIFIES_STATE, 3, {{"fd", PT_FD, PF_DEC}, {"pid", PT_PID, PF_DEC}, {"flags", PT_FLAGS32, PF_HEX}}}, [PPME_SYSCALL_INIT_MODULE_E] = {"init_module", EC_OTHER | EC_SYSCALL, EF_NONE, 0}, [PPME_SYSCALL_INIT_MODULE_X] = {"init_module", EC_OTHER | EC_SYSCALL, EF_NONE, 4, {{"res", PT_ERRNO, PF_DEC}, {"img", PT_BYTEBUF, PF_NA}, {"length", PT_UINT64, PF_DEC}, {"uargs", PT_CHARBUF, PF_NA}}}, [PPME_SYSCALL_FINIT_MODULE_E] = {"finit_module", EC_OTHER | EC_SYSCALL, EF_NONE, 0}, @@ -469,6 +471,7 @@ const struct ppm_event_info g_event_info[] = { [PPME_SYSCALL_MKNODAT_E] = {"mknodat", EC_OTHER | EC_SYSCALL, EF_NONE, 0}, [PPME_SYSCALL_MKNODAT_X] = {"mknodat", EC_OTHER | EC_SYSCALL, EF_USES_FD, 5, {{"res", PT_ERRNO, PF_DEC}, {"dirfd", PT_FD, PF_DEC}, {"path", PT_FSRELPATH, PF_NA, DIRFD_PARAM(1)},{"mode", PT_MODE, PF_OCT, mknod_mode},{"dev", PT_UINT32, PF_DEC}}}, }; +#pragma GCC diagnostic pop // We don't need this check in kmod (this source file is included during kmod compilation!) // This also avoids weird situation where the _Static_assert is not available in some very old compilers, diff --git a/driver/fillers_table.c b/driver/fillers_table.c index 805e2e8257..eb917f9a19 100644 --- a/driver/fillers_table.c +++ b/driver/fillers_table.c @@ -22,6 +22,8 @@ or GPL2.txt for full copies of the license. #define f_sys_socket_x f_sys_single_x +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = { [PPME_GENERIC_E] = {FILLER_REF(sys_generic)}, [PPME_GENERIC_X] = {FILLER_REF(sys_generic)}, @@ -354,3 +356,4 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = { [PPME_SYSCALL_MKNODAT_E] = {FILLER_REF(sys_empty)}, [PPME_SYSCALL_MKNODAT_X] = {FILLER_REF(sys_mknodat_x)} }; +#pragma GCC diagnostic pop diff --git a/test/libscap/helpers/engines.cpp b/test/libscap/helpers/engines.cpp index 2e2e6bc0a6..93a0a5a714 100644 --- a/test/libscap/helpers/engines.cpp +++ b/test/libscap/helpers/engines.cpp @@ -297,7 +297,7 @@ int num_possible_cpus(void) int n = 0; /* array of bools for each CPU */ - bool *mask; + bool* mask = nullptr; int err = parse_cpu_mask_file(fcpu, &mask, &n); if(err) return -1; diff --git a/userspace/libscap/linux/scap_cgroup.c b/userspace/libscap/linux/scap_cgroup.c index a43184ecf2..49b27ec6f9 100644 --- a/userspace/libscap/linux/scap_cgroup.c +++ b/userspace/libscap/linux/scap_cgroup.c @@ -788,7 +788,7 @@ static int32_t scap_cgroup_resolve_v2(struct scap_cgroup_interface* cgi, const c return SCAP_FAILURE; } - struct scap_cgroup_set found_subsystems = {.len = 0}; + struct scap_cgroup_set found_subsystems = {.len = 0, {'\0'}}; while(1) // not reached cgroup mountpoint yet { struct scap_cgroup_set current_subsystems; diff --git a/userspace/libsinsp/test/container_info.ut.cpp b/userspace/libsinsp/test/container_info.ut.cpp index b922b64250..c1fc7a2a8c 100644 --- a/userspace/libsinsp/test/container_info.ut.cpp +++ b/userspace/libsinsp/test/container_info.ut.cpp @@ -59,9 +59,12 @@ TEST_P(sinsp_container_lookup_test, delays_match) } } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" INSTANTIATE_TEST_CASE_P(sinsp_container_lookup, sinsp_container_lookup_test, ::testing::Values( std::tuple>{3, 500, {125, 250, 500}}, std::tuple>{5, 1000, {125, 250, 500, 1000, 1000}}, std::tuple>{2, 1, {1, 1}})); +#pragma GCC diagnostic pop diff --git a/userspace/libsinsp/utils.cpp b/userspace/libsinsp/utils.cpp index 4e7bc0278e..36c6f7e6d2 100644 --- a/userspace/libsinsp/utils.cpp +++ b/userspace/libsinsp/utils.cpp @@ -1080,7 +1080,7 @@ void sinsp_utils::ts_to_iso_8601(uint64_t ts, OUT std::string* res) bool sinsp_utils::parse_iso_8601_utc_string(const std::string& time_str, uint64_t &ns) { #ifndef _WIN32 - tm tm_time{0}; + tm tm_time{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; char* rem = strptime(time_str.c_str(), "%Y-%m-%dT%H:%M:", &tm_time); if(rem == NULL || *rem == '\0') { @@ -1112,7 +1112,7 @@ time_t get_epoch_utc_seconds(const std::string& time_str, const std::string& fmt { throw sinsp_exception("get_epoch_utc_seconds(): empty time or format string."); } - tm tm_time{0}; + tm tm_time{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; strptime(time_str.c_str(), fmt.c_str(), &tm_time); tm_time.tm_isdst = -1; // strptime does not set this, signal timegm to determine DST return timegm(&tm_time);