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(test,userspace): fixed strncat usage. #1113

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions test/drivers/start_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int open_engine(int argc, char** argv)
}
else if(optarg == NULL)
{
bpf_params.bpf_probe = strncat(cwd, BPF_PROBE_DEFAULT_PATH, FILENAME_MAX - strlen(cwd));
bpf_params.bpf_probe = strncat(cwd, BPF_PROBE_DEFAULT_PATH, FILENAME_MAX - strlen(cwd) - 1);
}
else
{
Expand Down Expand Up @@ -199,7 +199,7 @@ int open_engine(int argc, char** argv)
}
else if(optarg == NULL)
{
kmod_path = strncat(cwd, KMOD_DEFAULT_PATH, FILENAME_MAX - strlen(cwd));
kmod_path = strncat(cwd, KMOD_DEFAULT_PATH, FILENAME_MAX - strlen(cwd) - 1);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions userspace/libpman/src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ struct scap_stats_v2 *pman_get_scap_stats_v2(uint32_t flags, uint32_t *nstats, i
switch(stat)
{
case RUN_CNT:
strncat(g_state.stats[offset].name, modern_bpf_libbpf_stats_names[RUN_CNT], sizeof(g_state.stats[offset].name) - dest_len);
strncat(g_state.stats[offset].name, modern_bpf_libbpf_stats_names[RUN_CNT], sizeof(g_state.stats[offset].name) - dest_len - 1);
g_state.stats[offset].value.u64 = info.run_cnt;
break;
case RUN_TIME_NS:
strncat(g_state.stats[offset].name, modern_bpf_libbpf_stats_names[RUN_TIME_NS], sizeof(g_state.stats[offset].name) - dest_len);
strncat(g_state.stats[offset].name, modern_bpf_libbpf_stats_names[RUN_TIME_NS], sizeof(g_state.stats[offset].name) - dest_len - 1);
g_state.stats[offset].value.u64 = info.run_time_ns;
break;
case AVG_TIME_NS:
strncat(g_state.stats[offset].name, modern_bpf_libbpf_stats_names[AVG_TIME_NS], sizeof(g_state.stats[offset].name) - dest_len);
strncat(g_state.stats[offset].name, modern_bpf_libbpf_stats_names[AVG_TIME_NS], sizeof(g_state.stats[offset].name) - dest_len - 1);
g_state.stats[offset].value.u64 = 0;
if(info.run_cnt > 0)
{
Expand Down
6 changes: 3 additions & 3 deletions userspace/libscap/engine/bpf/scap_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,15 +1776,15 @@ const struct scap_stats_v2* scap_bpf_get_stats_v2(struct scap_engine_handle engi
switch(stat)
{
case RUN_CNT:
strncat(stats[offset].name, bpf_libbpf_stats_names[RUN_CNT], sizeof(stats[offset].name) - dest_len);
strncat(stats[offset].name, bpf_libbpf_stats_names[RUN_CNT], sizeof(stats[offset].name) - dest_len - 1);
stats[offset].value.u64 = info.run_cnt;
break;
case RUN_TIME_NS:
strncat(stats[offset].name, bpf_libbpf_stats_names[RUN_TIME_NS], sizeof(stats[offset].name) - dest_len);
strncat(stats[offset].name, bpf_libbpf_stats_names[RUN_TIME_NS], sizeof(stats[offset].name) - dest_len - 1);
stats[offset].value.u64 = info.run_time_ns;
break;
case AVG_TIME_NS:
strncat(stats[offset].name, bpf_libbpf_stats_names[AVG_TIME_NS], sizeof(stats[offset].name) - dest_len);
strncat(stats[offset].name, bpf_libbpf_stats_names[AVG_TIME_NS], sizeof(stats[offset].name) - dest_len - 1);
stats[offset].value.u64 = 0;
if (info.run_cnt > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions userspace/plugin/plugin_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ static inline void err_append(char* s, const char* suffix, const char* sep)
{
if (*s != '\0')
{
strncat(s, sep, PLUGIN_MAX_ERRLEN - strlen(sep));
strncat(s, sep, PLUGIN_MAX_ERRLEN - strlen(s) - 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondellaluce this should be good, right?
You want to check that you have enough space in dest (ie: s) to hold sep up until

PLUGIN_MAX_ERRLEN - strlen(s) - 1

bytes.
Same goes below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

}
strncat(s, suffix, PLUGIN_MAX_ERRLEN - strlen(suffix));
strncat(s, suffix, PLUGIN_MAX_ERRLEN - strlen(s) - 1);
}

static void* getsym(library_handle_t handle, const char* name)
Expand Down