Skip to content

Commit

Permalink
build: fix some more Clang warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Aponte <[email protected]>
  • Loading branch information
federico-sysdig authored and poiana committed Dec 11, 2023
1 parent 50131fb commit cc5cedd
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 30 deletions.
7 changes: 7 additions & 0 deletions cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
18 changes: 9 additions & 9 deletions driver/dynamic_params_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
37 changes: 20 additions & 17 deletions driver/event_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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} } },
Expand Down Expand Up @@ -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},
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions driver/fillers_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/libscap/helpers/engines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/linux/scap_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions userspace/libsinsp/test/container_info.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<short, short, std::vector<short>>{3, 500, {125, 250, 500}},
std::tuple<short, short, std::vector<short>>{5, 1000, {125, 250, 500, 1000, 1000}},
std::tuple<short, short, std::vector<short>>{2, 1, {1, 1}}));
#pragma GCC diagnostic pop
4 changes: 2 additions & 2 deletions userspace/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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')
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cc5cedd

Please sign in to comment.