]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
cpu plugin: Fix potential buffer overflow.
authorFlorian Forster <octo@collectd.org>
Tue, 28 Nov 2023 13:42:54 +0000 (14:42 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 29 Nov 2023 20:56:20 +0000 (21:56 +0100)
```
In function 'cpu_commit_without_aggregation',
    inlined from 'cpu_commit' at src/cpu.c:563:5,
    inlined from 'cpu_read' at src/cpu.c:925:3:
src/cpu.c:534:50: note: directive argument in the range [0, 18446744073709551614]
  534 |       snprintf(cpu_num_str, sizeof(cpu_num_str), "%zu", cpu_num);
      |                                                  ^~~~~
src/cpu.c:534:7: note: 'snprintf' output between 2 and 21 bytes into a destination of size 16
  534 |       snprintf(cpu_num_str, sizeof(cpu_num_str), "%zu", cpu_num);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

src/cpu.c

index 830f114157c0ff8cadb2827723ec575689bf6292..436d2c55a6d97b3d18f5c5b866c9f38ea06cb052 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -530,8 +530,8 @@ static void cpu_commit_without_aggregation(void) /* {{{ */
       if (!s->has_value)
         continue;
 
-      char cpu_num_str[16];
-      snprintf(cpu_num_str, sizeof(cpu_num_str), "%zu", cpu_num);
+      char cpu_num_str[32] = {0};
+      ssnprintf(cpu_num_str, sizeof(cpu_num_str), "%zu", cpu_num);
       metric_label_set(&m, "cpu", cpu_num_str);
 
       m.value.derive = s->conv.last_value.derive;