@cryptotaxi247 / netdata-1 / commits / 97ab996ec

fixes coverity identified issues (#4333)

Costa Tsaousis committed Sep 30, 2018 at 21:11 UTC 97ab996ec5e83a5284a38ef074ea8082347fb71a
4 files changed +15 -6
src/common.c
+2 -2
@@ -1442,7 +1442,7 @@ char *strdupz_path_subpath(const char *path, const char *subpath) {
1442 while(len > 0 && path[len - 1] == '/') len--;
1443
1444 // skip leading slashes in subpath
1445 - while(subpath && subpath[0] == '/') subpath++;
1445 + while(subpath[0] == '/') subpath++;
1446
1447 // if the last character in path is / and (there is a subpath or path is now empty)
1448 // keep the trailing slash in path and remove the additional slash
@@ -1458,7 +1458,7 @@ char *strdupz_path_subpath(const char *path, const char *subpath) {
1458 }
1459
1460 char buffer[FILENAME_MAX + 1];
1461 - snprintfz(buffer, FILENAME_MAX, "%.*s%s%s", (int)len, path, slash, (subpath)?subpath:"");
1461 + snprintfz(buffer, FILENAME_MAX, "%.*s%s%s", (int)len, path, slash, subpath);
1462 return strdupz(buffer);
1463 }
1464
src/dictionary.h
+3 -1
@@ -1,5 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 +#include "common.h"
4 +
5 #ifndef NETDATA_DICTIONARY_H
6 #define NETDATA_DICTIONARY_H 1
7
@@ -37,7 +39,7 @@ typedef struct dictionary {
39
40 extern DICTIONARY *dictionary_create(uint8_t flags);
41 extern void dictionary_destroy(DICTIONARY *dict);
40 -extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len);
42 +extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len) NEVERNULL;
43 extern void *dictionary_get(DICTIONARY *dict, const char *name);
44 extern int dictionary_del(DICTIONARY *dict, const char *name);
45
src/freeipmi_plugin.c
+2 -2
@@ -1529,8 +1529,8 @@ int main (int argc, char **argv) {
1529 int i, freq = 0;
1530 for(i = 1; i < argc ; i++) {
1531 if(isdigit(*argv[i]) && !freq) {
1532 - int n = atoi(argv[i]);
1533 - if(n > 0 && freq < 86400) {
1532 + int n = str2i(argv[i]);
1533 + if(n > 0 && n < 86400) {
1534 freq = n;
1535 continue;
1536 }
src/inlined.h
+8 -1
@@ -1,5 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 +#include "common.h"
4 +
5 #ifndef NETDATA_INLINED_H
6 #define NETDATA_INLINED_H 1
7
@@ -245,12 +247,17 @@ static inline char *strncpyz(char *dst, const char *src, size_t n) {
247 }
248
249 static inline int read_file(const char *filename, char *buffer, size_t size) {
250 + if(unlikely(!size)) return 3;
251 +
252 int fd = open(filename, O_RDONLY, 0666);
249 - if(unlikely(fd == -1))
253 + if(unlikely(fd == -1)) {
254 + buffer[0] = '\0';
255 return 1;
256 + }
257
258 ssize_t r = read(fd, buffer, size);
259 if(unlikely(r == -1)) {
260 + buffer[0] = '\0';
261 close(fd);
262 return 2;
263 }