When parsing the agent-check reply, we first loop on the response to find
the newline character, to add a NULL-byte at the end of the line. However,
this loop is not bounded to the data available in the buffer. So it is
possible to read bytes outside the buffer and eventually write a NULL-byte
ouside the buffer.
So let's check for the end of the buffer when looping on the agent-check
reply.
This patch must be backported to all stable versions.
const char *sc = NULL; /* maxconn */
const char *err = NULL; /* first error to report */
const char *wrn = NULL; /* first warning to report */
- char *cmd, *p;
+ char *cmd, *p, *end;
TRACE_ENTER(CHK_EV_TCPCHK_EXP, check);
*/
p = b_head(&check->bi);
- while (*p && *p != '\n' && *p != '\r')
+ end = b_tail(&check->bi);
+ while (p < end && *p && *p != '\n' && *p != '\r')
p++;
- if (!*p) {
+ if (!*p || p == end) {
if (!last_read)
goto wait_more_data;