Skip to content

Commit

Permalink
JSON_Read() warning messages enhancements (#1817)
Browse files Browse the repository at this point in the history
* JSON_Read() warning messages enhancements
* Change sprintf() to snprintf() per reviewer comment
  • Loading branch information
davidBar-On authored Jan 27, 2025
1 parent 49acc94 commit 9050d81
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 @@ -2778,6 +2778,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 @@ -2805,19 +2806,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");
snprintf(msg_buf, sizeof(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 {
snprintf(msg_buf, sizeof(msg_buf), "JSON data read failed; errno=%d", errno);
warning(msg_buf);
}
free(str);
}
}
}
else {
warning("JSON data length overflow");
snprintf(msg_buf, sizeof(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");
snprintf(msg_buf, sizeof(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 9050d81

Please sign in to comment.