Browse Source

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 5 years ago
parent
commit
9d41bd6ff2
1 changed files with 9 additions and 4 deletions
  1. 9 4
      health/health.c

+ 9 - 4
health/health.c

@@ -53,11 +53,16 @@ void health_silencers_init(void) {
             if (fd) {
                 char *str = mallocz((length+1)* sizeof(char));
                 if(str) {
-                    fread(str, sizeof(char), length, fd);
-                    str[length] = 0x00;
-                    json_parse(str, NULL, health_silencers_json_read_callback);
+                    size_t copied;
+                    copied = fread(str, sizeof(char), length, fd);
+                    if (copied == (length* sizeof(char))) {
+                        str[length] = 0x00;
+                        json_parse(str, NULL, health_silencers_json_read_callback);
+                        info("Parsed health silencers file %s", silencers_filename);
+                    } else {
+                        error("Cannot read the data from health silencers file %s", silencers_filename);
+                    }
                     freez(str);
-                    info("Parsed health silencers file %s", silencers_filename);
                 }
                 fclose(fd);
             } else {