enum healthcheck_status status;
struct buffer *msg = NULL;
struct ist desc = IST_NULL;
- char *ptr;
+ char *ptr, *end;
unsigned short nbytes = 0;
size_t msglen = 0;
* http://en.wikipedia.org/wiki/Basic_Encoding_Rules
* http://tools.ietf.org/html/rfc4511
*/
- ptr = b_head(&check->bi) + 1;
+ ptr = b_head(&check->bi);
+ end = ptr + b_data(&check->bi);
+ ptr++; /* First byte was already matched by the previous expect rule
+ * and at least 14 bytes are available
+ * (see do_parse_ldap_check_opt)
+ */
/* size of LDAPMessage */
if (*ptr & 0x80) {
* encode BindReponse length on 4 bytes.
*/
nbytes = (*ptr & 0x7f);
- if (b_data(&check->bi) < 1 + nbytes)
+ if (end - ptr < 1 + nbytes)
goto too_short;
switch (nbytes) {
case 4: msglen = read_n32(ptr+1); break;
msglen = *ptr;
ptr += 1 + nbytes;
- if (b_data(&check->bi) < 2 + nbytes + msglen)
+ if (end - ptr < msglen)
goto too_short;
/* http://tools.ietf.org/html/rfc4511#section-4.2.2
nbytes = 0;
if (*ptr & 0x80)
nbytes = (*ptr & 0x7f);
+
+ if (end - ptr < 1 + nbytes + 2 + 1)
+ goto too_short;
+
ptr += 1 + nbytes;
/* http://tools.ietf.org/html/rfc4511#section-4.1.9