Skip to content

Commit

Permalink
Changes per reviewer comments (with rebase)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Sep 12, 2024
1 parent 5b0ed63 commit d2a6ba6
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2800,35 +2800,40 @@ JSON_read(int fd)
* structure, NULL if there was an error.
*/
rc = Nread(fd, (char*) &nsize, sizeof(nsize), Ptcp);
hsize = ntohl(nsize);
if (rc == sizeof(nsize) && hsize > 0 && hsize <= MAX_PARAMS_JSON_STRING) {
/* Allocate a buffer to hold the JSON */
strsize = hsize + 1; /* +1 for trailing NULL */
if (strsize) {
str = (char *) calloc(sizeof(char), strsize);
if (str != NULL) {
rc = Nread(fd, str, hsize, Ptcp);
if (rc >= 0) {
/*
* We should be reading in the number of bytes corresponding to the
* length in that 4-byte integer. If we don't the socket might have
* prematurely closed. Only do the JSON parsing if we got the
* correct number of bytes.
*/
if (rc == hsize) {
json = cJSON_Parse(str);
}
else {
printf("WARNING: Size of data read does not correspond to offered length\n");
}
}
}
free(str);
if (rc == sizeof(nsize)) {
hsize = ntohl(nsize);
if (hsize > 0 && hsize <= MAX_PARAMS_JSON_STRING) {
/* Allocate a buffer to hold the JSON */
strsize = hsize + 1; /* +1 for trailing NULL */
if (strsize) {
str = (char *) calloc(sizeof(char), strsize);
if (str != NULL) {
rc = Nread(fd, str, hsize, Ptcp);
if (rc >= 0) {
/*
* We should be reading in the number of bytes corresponding to the
* length in that 4-byte integer. If we don't the socket might have
* prematurely closed. Only do the JSON parsing if we got the
* correct number of bytes.
*/
if (rc == hsize) {
json = cJSON_Parse(str);
}
else {
printf("WARNING: JSON size of data read does not correspond to offered length\n");
}
}
free(str);
}
}
}
else {
printf("WARNING: Data length overflow\n");
printf("WARNING: JSON data length overflow\n");
}
}
else {
printf("WARNING: Failed to read JSN data size\n");
}
return json;
}

Expand Down

0 comments on commit d2a6ba6

Please sign in to comment.