Skip to content

Commit 9050d81

Browse files
authored
JSON_Read() warning messages enhancements (#1817)
* JSON_Read() warning messages enhancements * Change sprintf() to snprintf() per reviewer comment
1 parent 49acc94 commit 9050d81

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/iperf_api.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,7 @@ JSON_read(int fd, int max_size)
27782778
char *str;
27792779
cJSON *json = NULL;
27802780
int rc;
2781+
char msg_buf[WARN_STR_LEN * 2];
27812782

27822783
/*
27832784
* Read a four-byte integer, which is the length of the JSON to follow.
@@ -2805,19 +2806,27 @@ JSON_read(int fd, int max_size)
28052806
json = cJSON_Parse(str);
28062807
}
28072808
else {
2808-
warning("JSON size of data read does not correspond to offered length");
2809+
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);
2810+
warning(msg_buf);
28092811
}
28102812
}
2813+
else {
2814+
snprintf(msg_buf, sizeof(msg_buf), "JSON data read failed; errno=%d", errno);
2815+
warning(msg_buf);
2816+
}
28112817
free(str);
28122818
}
28132819
}
28142820
}
28152821
else {
2816-
warning("JSON data length overflow");
2822+
snprintf(msg_buf, sizeof(msg_buf), "JSON data length overflow - %d bytes JSON size is not allowed", hsize);
2823+
warning(msg_buf);
28172824
}
28182825
}
28192826
else {
28202827
warning("Failed to read JSON data size");
2828+
snprintf(msg_buf, sizeof(msg_buf), "Failed to read JSON data size - read returned %d; errno=%d", rc, errno);
2829+
warning(msg_buf);
28212830
}
28222831
return json;
28232832
}

0 commit comments

Comments
 (0)