Skip to content

Commit

Permalink
fix(test,userspace): fixed strncat usage.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed May 24, 2023
1 parent bcb51cc commit 3e5dab3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
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);
}
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

0 comments on commit 3e5dab3

Please sign in to comment.