@cryptotaxi247 / netdata-1 / commits / 9d41bd6ff

Health could not read properly the health silencers file (#6374)

* Health_alert The file health/healht.c on line 56 did not check the return of the fread , so Netdata could work with incomplete data * Health_alert The free functions was initially called in a wrong place.

thiagoftsm committed Jul 3, 2019 at 17:48 UTC 9d41bd6ff2ae6b8c3b20605efc55275eae4af46d
1 file changed +9 -4
health/health.c
+9 -4
@@ -53,11 +53,16 @@ void health_silencers_init(void) {
53 if (fd) {
54 char *str = mallocz((length+1)* sizeof(char));
55 if(str) {
56 - fread(str, sizeof(char), length, fd);
57 - str[length] = 0x00;
58 - json_parse(str, NULL, health_silencers_json_read_callback);
56 + size_t copied;
57 + copied = fread(str, sizeof(char), length, fd);
58 + if (copied == (length* sizeof(char))) {
59 + str[length] = 0x00;
60 + json_parse(str, NULL, health_silencers_json_read_callback);
61 + info("Parsed health silencers file %s", silencers_filename);
62 + } else {
63 + error("Cannot read the data from health silencers file %s", silencers_filename);
64 + }
65 freez(str);
60 - info("Parsed health silencers file %s", silencers_filename);
66 }
67 fclose(fd);
68 } else {