diff --git a/test/drivers/start_tests.cpp b/test/drivers/start_tests.cpp index 2b2a6ace07..c8b54216e8 100644 --- a/test/drivers/start_tests.cpp +++ b/test/drivers/start_tests.cpp @@ -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 { @@ -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 { diff --git a/userspace/libpman/src/stats.c b/userspace/libpman/src/stats.c index c1af303bb1..412ab759c8 100644 --- a/userspace/libpman/src/stats.c +++ b/userspace/libpman/src/stats.c @@ -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) { diff --git a/userspace/libscap/engine/bpf/scap_bpf.c b/userspace/libscap/engine/bpf/scap_bpf.c index 9d52cf21f2..3eb8672ed0 100644 --- a/userspace/libscap/engine/bpf/scap_bpf.c +++ b/userspace/libscap/engine/bpf/scap_bpf.c @@ -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) { diff --git a/userspace/plugin/plugin_loader.c b/userspace/plugin/plugin_loader.c index eac60f7c4b..37f3570d9e 100644 --- a/userspace/plugin/plugin_loader.c +++ b/userspace/plugin/plugin_loader.c @@ -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)