Adjust buffers to prevent overflow (#15025)
* Adjust buffers to prevent overflow * Adjust strncat parameter to prevent buffer overflow
Stelios Fragkakis committed
May 10, 2023 at 12:57 UTC
836a56a956f252935dd2ed4908aab57e1a95ccaf
3 files changed
+7
-7
collectors/cgroups.plugin/sys_fs_cgroup.c
+2
-2
@@ -1952,7 +1952,7 @@ static void is_cgroup_procs_exist(netdata_ebpf_cgroup_shm_body_t *out, char *id)
1952
}
1953
1954
static inline void convert_cgroup_to_systemd_service(struct cgroup *cg) {
1955
- char buffer[CGROUP_CHARTID_LINE_MAX];
1955
+ char buffer[CGROUP_CHARTID_LINE_MAX + 1];
1956
cg->options |= CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE;
1957
strncpyz(buffer, cg->id, CGROUP_CHARTID_LINE_MAX);
1958
char *s = buffer;
@@ -2607,7 +2607,7 @@ static inline void discovery_process_first_time_seen_cgroup(struct cgroup *cg) {
2607
}
2608
cg->first_time_seen = 0;
2609
2610
- char comm[TASK_COMM_LEN];
2610
+ char comm[TASK_COMM_LEN + 1];
2611
2612
if (cg->container_orchestrator == CGROUPS_ORCHESTRATOR_UNSET) {
2613
if (strstr(cg->id, "kubepods")) {
collectors/proc.plugin/proc_diskstats.c
+4
-4
@@ -348,7 +348,7 @@ static inline int get_disk_name_from_path(const char *path, char *result, size_t
348
349
int found = 0, preferred = 0;
350
351
- char *first_result = mallocz(result_size);
351
+ char *first_result = mallocz(result_size + 1);
352
353
DIR *dir = opendir(path);
354
if (!dir) {
@@ -454,7 +454,7 @@ failed:
454
}
455
456
static inline char *get_disk_name(unsigned long major, unsigned long minor, char *disk) {
457
- char result[FILENAME_MAX + 1] = "";
457
+ char result[FILENAME_MAX + 2] = "";
458
459
if(!path_to_device_mapper || !*path_to_device_mapper || !get_disk_name_from_path(path_to_device_mapper, result, FILENAME_MAX + 1, major, minor, disk, NULL, 0))
460
if(!path_to_device_label || !*path_to_device_label || !get_disk_name_from_path(path_to_device_label, result, FILENAME_MAX + 1, major, minor, disk, NULL, 0))
@@ -615,8 +615,8 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
615
// read device uuid if it is an LVM volume
616
if (!strncmp(d->device, "dm-", 3)) {
617
char uuid_filename[FILENAME_MAX + 1];
618
- snprintfz(uuid_filename, FILENAME_MAX, path_to_sys_devices_virtual_block_device, disk);
619
- strncat(uuid_filename, "/dm/uuid", FILENAME_MAX);
618
+ int size = snprintfz(uuid_filename, FILENAME_MAX, path_to_sys_devices_virtual_block_device, disk);
619
+ strncat(uuid_filename, "/dm/uuid", FILENAME_MAX - size);
620
621
char device_uuid[RRD_ID_LENGTH_MAX + 1];
622
if (!read_file(uuid_filename, device_uuid, RRD_ID_LENGTH_MAX) && !strncmp(device_uuid, "LVM-", 4)) {
database/rrdset.c
+1
-1
@@ -2207,7 +2207,7 @@ bool rrdset_memory_load_or_create_map_save(RRDSET *st, RRD_MEMORY_MODE memory_mo
2207
memset(st_on_file, 0, size);
2208
2209
// set the values we need
2210
- strncpyz(st_on_file->id, rrdset_id(st), RRD_ID_LENGTH_MAX_V019 + 1);
2210
+ strncpyz(st_on_file->id, rrdset_id(st), RRD_ID_LENGTH_MAX_V019);
2211
strcpy(st_on_file->cache_filename, fullfilename);
2212
strcpy(st_on_file->magic, RRDSET_MAGIC_V019);
2213
st_on_file->memsize = size;