Ebpf coverity (#8135)
* Fix coverity errors on libnetdata/ebpf * Fix coverity warnings inside ebpf collector
thiagoftsm committed
Feb 19, 2020 at 18:10 UTC
1f345aac5e6fb342a3db326770c5576fad26d9d4
2 files changed
+12
-7
collectors/ebpf_process.plugin/ebpf_process.c
+5
-5
@@ -170,11 +170,11 @@ static void int_exit(int sig)
170
dup2 (fd, STDIN_FILENO);
171
dup2 (fd, STDOUT_FILENO);
172
dup2 (fd, STDERR_FILENO);
173
-
174
- if (fd > 2)
175
- close (fd);
173
}
174
175
+ if (fd > 2)
176
+ close (fd);
177
+
178
int sid = setsid();
179
if(sid >= 0) {
180
sleep(1);
@@ -213,9 +213,9 @@ static inline void netdata_write_chart_cmd(char *type
213
, order);
214
}
215
216
-static void netdata_write_global_dimension(char *dimension, char *name)
216
+static void netdata_write_global_dimension(char *d, char *n)
217
{
218
- printf("DIMENSION %s %s absolute 1 1\n", dimension, name);
218
+ printf("DIMENSION %s %s absolute 1 1\n", d, n);
219
}
220
221
static void netdata_create_global_dimension(void *ptr, int end)
libnetdata/ebpf/ebpf.c
+7
-2
@@ -62,9 +62,11 @@ int get_kernel_version() {
62
if (fd < 0)
63
return -1;
64
65
- ssize_t len = read(fd, version, sizeof(version));
66
- if (len < 0)
65
+ ssize_t len = read(fd, ver, sizeof(ver));
66
+ if (len < 0) {
67
+ close(fd);
68
return -1;
69
+ }
70
71
close(fd);
72
@@ -79,6 +81,9 @@ int get_kernel_version() {
81
82
if (*version)
83
version++;
84
+ else
85
+ return -1;
86
+
87
move = patch;
88
while (*version) *move++ = *version++;
89
*move = '\0';