Skip to content

Commit

Permalink
JSON_Read() warning messages enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Jan 5, 2025
1 parent e4cb673 commit aa9b150
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,7 @@ JSON_read(int fd, int max_size)
char *str;
cJSON *json = NULL;
int rc;
char msg_buf[WARN_STR_LEN * 2];

/*
* Read a four-byte integer, which is the length of the JSON to follow.
Expand Down Expand Up @@ -2788,19 +2789,27 @@ JSON_read(int fd, int max_size)
json = cJSON_Parse(str);
}
else {
warning("JSON size of data read does not correspond to offered length");
sprintf(msg_buf, "JSON size of data read does not correspond to offered length - expected %d bytes but received %d; errno=%d", hsize, rc, errno);
warning(msg_buf);
}
}
else {
sprintf(msg_buf, "JSON data read failed; errno=%d", errno);
warning(msg_buf);
}
free(str);
}
}
}
else {
warning("JSON data length overflow");
sprintf(msg_buf, "JSON data length overflow - %d bytes JSON size is not allowed", hsize);
warning(msg_buf);
}
}
else {
warning("Failed to read JSON data size");
sprintf(msg_buf, "Failed to read JSON data size - read returned %d; errno=%d", rc, errno);
warning(msg_buf);
}
return json;
}
Expand Down

0 comments on commit aa9b150

Please sign in to comment.