Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extract): always return a pointer to the first element of the vector #25

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions include/falcosecurity/extract_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,16 @@ class extract_request
FALCOSECURITY_INLINE
void set_value(bool v, size_t pos, bool copy)
{
// The resize always ensure we have enough space in our vectors for
// data we have to copy.
resize_result(pos);
auto r = reinterpret_cast<_internal::ss_plugin_bool*>(m_result.data());
// Please note that every element of `m_result` is on at least 8 bytes (see union result).
// Here we are casting it to a vector of `uint32_t` so we are writing an element every 4 bytes.
r[pos] = (_internal::ss_plugin_bool)(v ? 1 : 0);
m_req->res.boolean = &r[pos];
// `m_req` contains the pointer to the `ss_plugin_extract_field` array obtained
// from the framework. The sdk always returns a pointer to an internal array.
m_req->res.boolean = &r[0];
m_req->res_len = pos + 1;
}

Expand All @@ -192,7 +198,7 @@ class extract_request
resize_result(pos);
auto r = reinterpret_cast<uint64_t*>(m_result.data());
r[pos] = v;
m_req->res.u64 = &r[pos];
m_req->res.u64 = &r[0];
m_req->res_len = pos + 1;
}

Expand All @@ -210,7 +216,7 @@ class extract_request
{
r[pos] = v;
}
m_req->res.str = &r[pos];
m_req->res.str = &r[0];
m_req->res_len = pos + 1;
}

Expand All @@ -235,7 +241,7 @@ class extract_request
r[pos].ptr = buf;
r[pos].len = (uint32_t)bufsize;
}
m_req->res.buf = &r[pos];
m_req->res.buf = &r[0];
m_req->res_len = pos + 1;
}

Expand Down