Skip to content

Commit

Permalink
build: fix several compiler 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 Nov 28, 2023
1 parent 4a57dbd commit 0287743
Show file tree
Hide file tree
Showing 25 changed files with 137 additions and 127 deletions.
2 changes: 1 addition & 1 deletion userspace/libsinsp/container_engine/docker/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class sinsp_threadinfo;
namespace libsinsp {
namespace container_engine {

class docker_lookup_request;
struct docker_lookup_request;

class docker_base : public container_engine_base
{
Expand Down
14 changes: 6 additions & 8 deletions userspace/libsinsp/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ limitations under the License.

#pragma once

#include <set>
#include <string>
#include <vector>
#include "filter_check_list.h"
#include "gen_filter.h"
#include "filter/parser.h"

#include <set>
#include <string>
#include <vector>

/** @defgroup filter Filtering events
* Filtering infrastructure.
* @{
Expand Down Expand Up @@ -145,10 +146,8 @@ class sinsp_filter_factory : public gen_event_filter_factory

virtual ~sinsp_filter_factory();

gen_event_filter *new_filter();

gen_event_filter_check *new_filtercheck(const char *fldname);

gen_event_filter* new_filter() override;
gen_event_filter_check* new_filtercheck(const char* fldname) override;
std::list<gen_event_filter_factory::filter_fieldclass_info> get_fields() override;

// Convienence method to convert a vector of
Expand All @@ -162,4 +161,3 @@ class sinsp_filter_factory : public gen_event_filter_factory
sinsp *m_inspector;
filter_check_list &m_available_checks;
};

11 changes: 5 additions & 6 deletions userspace/libsinsp/gen_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,20 @@ class gen_event_filter_expression : public gen_event_filter_check
// The following methods are part of the filter check interface but are irrelevant
// for this class, because they are used only for the leaves of the filtering tree.
//
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering)
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering) override
{
return 0;
}

void add_filter_value(const char* str, uint32_t len, uint32_t i = 0 )
void add_filter_value(const char* str, uint32_t len, uint32_t i = 0) override
{
return;
}

void add_check(gen_event_filter_check* chk);

bool compare(gen_event *evt);
bool compare(gen_event*) override;
bool extract(gen_event*, std::vector<extract_value_t>& values, bool sanitize_strings = true) override;

bool extract(gen_event *evt, std::vector<extract_value_t>& values, bool sanitize_strings = true);
void add_check(gen_event_filter_check* chk);

//
// An expression is consistent if all its checks are of the same type (or/and).
Expand Down
28 changes: 11 additions & 17 deletions userspace/libsinsp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,21 @@ void sinsp_logger::log(std::string msg, const severity sev)

if(gettimeofday(&ts, nullptr) == 0)
{
const std::string::size_type ts_length = sizeof("31-12 23:59:59.999999 ");
char ts_buf[ts_length];
struct tm* ti;
struct tm time_info = {};

#ifdef _WIN32
ti = _gmtime32((__time32_t*)&ts.tv_sec);
tm* ti = _gmtime32((__time32_t*)&ts.tv_sec);
#else
tm time_info;
gmtime_r(&ts.tv_sec, &time_info);
ti = &time_info;
tm* ti = &time_info;
#endif

snprintf(ts_buf,
sizeof(ts_buf),
"%.2d-%.2d %.2d:%.2d:%.2d.%.6d ",
ti->tm_mon + 1,
ti->tm_mday,
ti->tm_hour,
ti->tm_min,
ti->tm_sec,
(int)ts.tv_usec);
char ts_buf[80]; // holds date/time string: "31-12 23:59:59.999999 "
snprintf(ts_buf, sizeof(ts_buf), "%.2d-%.2d %.2d:%.2d:%.2d.%.6d ",
ti->tm_mon + 1,
ti->tm_mday,
ti->tm_hour,
ti->tm_min,
ti->tm_sec,
(int)ts.tv_usec);

ts_buf[sizeof(ts_buf) - 1] = '\0';
msg.insert(0, ts_buf);
Expand Down
24 changes: 12 additions & 12 deletions userspace/libsinsp/plugin_filtercheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ limitations under the License.
*/

using namespace std;

#include "plugin_filtercheck.h"
#include "plugin_manager.h"

using namespace std;

sinsp_filter_check_plugin::sinsp_filter_check_plugin()
{
m_info.m_name = "plugin";
Expand Down Expand Up @@ -70,7 +70,7 @@ int32_t sinsp_filter_check_plugin::parse_field_name(const char* str, bool alloc_
val = val.substr(0, val_end);
}
trim(val);

// search for the field's argument
size_t arg_len = 0;
size_t arg_pos = val.find_first_of('[', 0);
Expand Down Expand Up @@ -104,7 +104,7 @@ int32_t sinsp_filter_check_plugin::parse_field_name(const char* str, bool alloc_
throw sinsp_exception(string("filter '") + string(str) + string("': ")
+ m_field->m_name + string(" does not allow nor require an argument but one is provided: " + m_argstr));
}

// parse the argument content, which can either be an index or a key
if(m_info.m_fields[m_field_id].m_flags & filtercheck_field_flags::EPF_ARG_INDEX)
{
Expand All @@ -118,7 +118,7 @@ int32_t sinsp_filter_check_plugin::parse_field_name(const char* str, bool alloc_
// update the parsed len taking into account both the name and the argument
res = arg_pos + arg_len + 2;
}

if (!m_arg_present && (m_info.m_fields[m_field_id].m_flags & filtercheck_field_flags::EPF_ARG_REQUIRED))
{
throw sinsp_exception(string("filter '") + string(str) + string("': ") + m_field->m_name + string(" requires an argument but none provided"));
Expand Down Expand Up @@ -232,14 +232,14 @@ void sinsp_filter_check_plugin::extract_arg_index(const char* full_field_name)
int length = m_argstr.length();
bool is_valid = true;
std::string message = "";
// Please note that numbers starting with `0` (`01`, `02`, `0003`, ...) are not indexes.

// Please note that numbers starting with `0` (`01`, `02`, `0003`, ...) are not indexes.
if(length == 0 || (length > 1 && m_argstr[0] == '0'))
{
is_valid = false;
message = " has an invalid index argument starting with 0: ";
}

// The index must be composed only by digits (0-9).
for(int j = 0; j < length; j++)
{
Expand All @@ -252,16 +252,16 @@ void sinsp_filter_check_plugin::extract_arg_index(const char* full_field_name)
}

// If the argument is valid we can convert it with `stoul`.
// Please note that `stoul` alone is not enough, since it also consider as valid
// strings like "0123 i'm a number", converting them into '0123'. This is why in the
// Please note that `stoul` alone is not enough, since it also consider as valid
// strings like "0123 i'm a number", converting them into '0123'. This is why in the
// previous step we check that every character is a digit.
if(is_valid)
{
try
{
m_arg_index = std::stoul(m_argstr);
return;
}
}
catch(...)
{
message = " has an invalid index argument not representable on 64 bit: ";
Expand All @@ -272,7 +272,7 @@ void sinsp_filter_check_plugin::extract_arg_index(const char* full_field_name)
}

// extract_arg_key() extracts a valid string from the argument. If we pass
// a numeric argument, it will be converted to string.
// a numeric argument, it will be converted to string.
void sinsp_filter_check_plugin::extract_arg_key()
{
m_arg_key = (char*)m_argstr.c_str();
Expand Down
6 changes: 3 additions & 3 deletions userspace/libsinsp/sinsp_filtercheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ int32_t sinsp_filter_check::parse_field_name(const char* str, bool alloc_state,
/* Here we are searching for the longest match */
if(strncmp(str, m_info.m_fields[j].m_name, fldlen) == 0)
{
/* we found some info about the required field, we save it in this way
/* we found some info about the required field, we save it in this way
* we don't have to loop again through the fields.
*/
m_field_id = j;
Expand Down Expand Up @@ -1264,7 +1264,7 @@ bool sinsp_filter_check::flt_compare(cmpop op, ppm_param_type type, std::vector<
{
item.first = it.ptr;
item.second = it.len;

// note: PT_IPNET would not work with simple memcmp comparison
// todo(jasondellaluce): refactor filter_value_t to actually use flt_compare instead of memcmp.
if (type == PT_IPNET)
Expand Down Expand Up @@ -1431,7 +1431,7 @@ bool sinsp_filter_check::extract(sinsp_evt *evt, OUT std::vector<extract_value_t
{
values.clear();
extract_value_t val;
val.ptr = extract(evt, &val.len, sanitize_string);
val.ptr = extract(evt, &val.len, sanitize_strings);
if (val.ptr != NULL)
{
values.push_back(val);
Expand Down
23 changes: 10 additions & 13 deletions userspace/libsinsp/sinsp_filtercheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ class sinsp_filter_check : public gen_event_filter_check
{
public:
sinsp_filter_check();

virtual ~sinsp_filter_check()
{
}
virtual ~sinsp_filter_check() = default;

//
// Allocate a new check of the same type.
Expand All @@ -97,13 +94,13 @@ class sinsp_filter_check : public gen_event_filter_check
// Returns the length of the parsed field if successful, an exception in
// case of error.
//
virtual int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering);
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering) override;

//
// If this check is used by a filter, extract the constant to compare it to
// Doesn't return the field length because the filtering engine can calculate it.
//
void add_filter_value(const char* str, uint32_t len, uint32_t i = 0 );
void add_filter_value(const char* str, uint32_t len, uint32_t i = 0) override;
virtual size_t parse_filter_value(const char* str, uint32_t len, uint8_t *storage, uint32_t storage_len);

//
Expand All @@ -120,14 +117,14 @@ class sinsp_filter_check : public gen_event_filter_check
// Extract the field from the event. In sanitize_strings is true, any
// string values are sanitized to remove nonprintable characters.
//
bool extract(gen_event *evt, OUT std::vector<extract_value_t>& values, bool sanitize_strings = true);
bool extract(gen_event*, OUT std::vector<extract_value_t>& values, bool sanitize_strings = true) override;

// Alias of extract that uses the sinsp_evt type.
// By default, this fills the vector with only one value, retireved by calling the single-result
// extract method.
// If a NULL value is returned by extract, the vector is emptied.
// Subclasses are meant to either override this, or the single-valued extract method.
virtual bool extract(sinsp_evt *evt, OUT std::vector<extract_value_t>& values, bool sanitize_strings = true);
virtual bool extract(sinsp_evt*, OUT std::vector<extract_value_t>& values, bool sanitize_strings = true);

//
// Wrapper for extract() that implements caching to speed up multiple extractions of the same value,
Expand All @@ -139,16 +136,16 @@ class sinsp_filter_check : public gen_event_filter_check
// Extract the field as json from the event (by default, fall
// back to the regular extract functionality)
//
virtual Json::Value extract_as_js(sinsp_evt *evt, OUT uint32_t* len)
virtual Json::Value extract_as_js(sinsp_evt*, OUT uint32_t* len)
{
return Json::nullValue;
}

//
// Compare the field with the constant value obtained from parse_filter_value()
//
bool compare(gen_event *evt);
virtual bool compare(sinsp_evt *evt);
bool compare(gen_event*) override;
virtual bool compare(sinsp_evt*);

//
// Extract the value from the event and convert it into a string
Expand All @@ -172,8 +169,8 @@ class sinsp_filter_check : public gen_event_filter_check
// This is a single-value version of extract for subclasses non supporting extracting
// multiple values. By default, this returns NULL.
// Subclasses are meant to either override this, or the multi-valued extract method.
virtual uint8_t* extract(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings = true);
virtual uint8_t* extract(sinsp_evt*, OUT uint32_t* len, bool sanitize_strings = true);

bool flt_compare(cmpop op, ppm_param_type type, void* operand1, uint32_t op1_len = 0, uint32_t op2_len = 0);
bool flt_compare(cmpop op, ppm_param_type type, std::vector<extract_value_t>& values, uint32_t op2_len = 0);

Expand Down
10 changes: 6 additions & 4 deletions userspace/libsinsp/sinsp_filtercheck_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ class sinsp_filter_check_container : public sinsp_filter_check
};

sinsp_filter_check_container();
sinsp_filter_check* allocate_new();
uint8_t* extract(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings = true);

const std::string &get_argstr();
sinsp_filter_check* allocate_new() override;
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering) override;
uint8_t* extract(sinsp_evt*, OUT uint32_t* len, bool sanitize_strings = true) override;

const std::string& get_argstr();

private:
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering);
int32_t extract_arg(const std::string& val, size_t basename);

std::string m_tstr;
Expand Down
16 changes: 9 additions & 7 deletions userspace/libsinsp/sinsp_filtercheck_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ class sinsp_filter_check_event : public sinsp_filter_check

sinsp_filter_check_event();
~sinsp_filter_check_event();
sinsp_filter_check* allocate_new();
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering);
size_t parse_filter_value(const char* str, uint32_t len, uint8_t *storage, uint32_t storage_len);

sinsp_filter_check* allocate_new() override;
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering) override;
size_t parse_filter_value(const char* str, uint32_t len, uint8_t* storage, uint32_t storage_len) override;
const filtercheck_field_info* get_field_info() override;
uint8_t* extract(sinsp_evt*, OUT uint32_t* len, bool sanitize_strings = true) override;
Json::Value extract_as_js(sinsp_evt*, OUT uint32_t* len) override;
bool compare(sinsp_evt*) override;

void validate_filter_value(const char* str, uint32_t len);
const filtercheck_field_info* get_field_info();
uint8_t* extract(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings = true);
Json::Value extract_as_js(sinsp_evt *evt, OUT uint32_t* len);
bool compare(sinsp_evt *evt);

uint64_t m_u64val;
int64_t m_s64val;
Expand Down
7 changes: 4 additions & 3 deletions userspace/libsinsp/sinsp_filtercheck_evtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ class sinsp_filter_check_evtin : public sinsp_filter_check

sinsp_filter_check_evtin();
~sinsp_filter_check_evtin();
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering);
sinsp_filter_check* allocate_new();
uint8_t* extract(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings = true);

sinsp_filter_check* allocate_new() override;
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering) override;
uint8_t* extract(sinsp_evt*, OUT uint32_t* len, bool sanitize_strings = true) override;

std::string m_argname;
int32_t m_argid;
Expand Down
22 changes: 12 additions & 10 deletions userspace/libsinsp/sinsp_filtercheck_fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,12 @@ class sinsp_filter_check_fd : public sinsp_filter_check
};

sinsp_filter_check_fd();
sinsp_filter_check* allocate_new();
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering);
bool extract(sinsp_evt *evt, OUT std::vector<extract_value_t>& values, bool sanitize_strings = true);
uint8_t* extract(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings = true);
int32_t extract_arg(std::string fldname, std::string val);
bool compare_ip(sinsp_evt *evt);
bool compare_net(sinsp_evt *evt);
bool compare_port(sinsp_evt *evt);
bool compare_domain(sinsp_evt *evt);
bool compare(sinsp_evt *evt);

sinsp_filter_check* allocate_new() override;
int32_t parse_field_name(const char* str, bool alloc_state, bool needed_for_filtering) override;
bool extract(sinsp_evt*, OUT std::vector<extract_value_t>& values, bool sanitize_strings = true) override;
uint8_t* extract(sinsp_evt*, OUT uint32_t* len, bool sanitize_strings = true) override;
bool compare(sinsp_evt*) override;

sinsp_threadinfo* m_tinfo;
sinsp_fdinfo_t* m_fdinfo;
Expand All @@ -111,7 +107,13 @@ class sinsp_filter_check_fd : public sinsp_filter_check
uint64_t m_conv_uint64;

private:
int32_t extract_arg(std::string fldname, std::string val);
uint8_t* extract_from_null_fd(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings);
bool extract_fdname_from_creator(sinsp_evt *evt, OUT uint32_t* len, bool sanitize_strings, bool fd_nameraw = false);
bool extract_fd(sinsp_evt *evt);

bool compare_ip(sinsp_evt *evt);
bool compare_net(sinsp_evt *evt);
bool compare_port(sinsp_evt *evt);
bool compare_domain(sinsp_evt *evt);
};
Loading

0 comments on commit 0287743

Please sign in to comment.