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.
This commit is contained in:
thiagoftsm 2019-07-03 17:48:06 +00:00 committed by GitHub
parent bbb33ab418
commit 9d41bd6ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -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 {