WPS: Add more debug prints to httpread

These can be helpful when debugging HTTP error cases.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2015-04-28 17:30:08 +03:00
parent 1bd0d578a9
commit 8640cf7f8f

View file

@ -380,8 +380,11 @@ static void httpread_read_handler(int sd, void *eloop_ctx, void *sock_ctx)
*/ */
wpa_printf(MSG_DEBUG, "httpread: Trying to read more data(%p)", h); wpa_printf(MSG_DEBUG, "httpread: Trying to read more data(%p)", h);
nread = read(h->sd, readbuf, sizeof(readbuf)); nread = read(h->sd, readbuf, sizeof(readbuf));
if (nread < 0) if (nread < 0) {
wpa_printf(MSG_DEBUG, "httpread failed: %s", strerror(errno));
goto bad; goto bad;
}
wpa_hexdump_ascii(MSG_MSGDUMP, "httpread - read", readbuf, nread);
if (nread == 0) { if (nread == 0) {
/* end of transmission... this may be normal /* end of transmission... this may be normal
* or may be an error... in some cases we can't * or may be an error... in some cases we can't
@ -424,6 +427,8 @@ static void httpread_read_handler(int sd, void *eloop_ctx, void *sock_ctx)
if (nread == 0) if (nread == 0)
goto get_more; goto get_more;
if (h->hdr_nbytes == HTTPREAD_HEADER_MAX_SIZE) { if (h->hdr_nbytes == HTTPREAD_HEADER_MAX_SIZE) {
wpa_printf(MSG_DEBUG,
"httpread: Too long header");
goto bad; goto bad;
} }
*hbp++ = *rbp++; *hbp++ = *rbp++;
@ -485,8 +490,12 @@ static void httpread_read_handler(int sd, void *eloop_ctx, void *sock_ctx)
char *new_body; char *new_body;
int new_alloc_nbytes; int new_alloc_nbytes;
if (h->body_nbytes >= h->max_bytes) if (h->body_nbytes >= h->max_bytes) {
wpa_printf(MSG_DEBUG,
"httpread: body_nbytes=%d >= max_bytes=%d",
h->body_nbytes, h->max_bytes);
goto bad; goto bad;
}
new_alloc_nbytes = h->body_alloc_nbytes + new_alloc_nbytes = h->body_alloc_nbytes +
HTTPREAD_BODYBUF_DELTA; HTTPREAD_BODYBUF_DELTA;
/* For content-length case, the first time /* For content-length case, the first time
@ -504,8 +513,12 @@ static void httpread_read_handler(int sd, void *eloop_ctx, void *sock_ctx)
goto bad; goto bad;
} }
if ((new_body = os_realloc(h->body, new_alloc_nbytes)) if ((new_body = os_realloc(h->body, new_alloc_nbytes))
== NULL) == NULL) {
wpa_printf(MSG_DEBUG,
"httpread: Failed to reallocate buffer (len=%d)",
new_alloc_nbytes);
goto bad; goto bad;
}
h->body = new_body; h->body = new_body;
h->body_alloc_nbytes = new_alloc_nbytes; h->body_alloc_nbytes = new_alloc_nbytes;
@ -524,8 +537,11 @@ static void httpread_read_handler(int sd, void *eloop_ctx, void *sock_ctx)
/* hdr line consists solely /* hdr line consists solely
* of a hex numeral and CFLF * of a hex numeral and CFLF
*/ */
if (!isxdigit(*cbp)) if (!isxdigit(*cbp)) {
wpa_printf(MSG_DEBUG,
"httpread: Unexpected chunk header value (not a hex digit)");
goto bad; goto bad;
}
h->chunk_size = strtoul(cbp, NULL, 16); h->chunk_size = strtoul(cbp, NULL, 16);
if (h->chunk_size < 0 || if (h->chunk_size < 0 ||
h->chunk_size > h->max_bytes) { h->chunk_size > h->max_bytes) {
@ -563,8 +579,11 @@ static void httpread_read_handler(int sd, void *eloop_ctx, void *sock_ctx)
*/ */
if (bbp[-1] == '\n' && if (bbp[-1] == '\n' &&
bbp[-2] == '\r') { bbp[-2] == '\r') {
} else } else {
wpa_printf(MSG_DEBUG,
"httpread: Invalid chunk end");
goto bad; goto bad;
}
h->body_nbytes -= 2; h->body_nbytes -= 2;
bbp -= 2; bbp -= 2;
h->chunk_start = h->body_nbytes; h->chunk_start = h->body_nbytes;
@ -668,11 +687,14 @@ bad:
return; return;
get_more: get_more:
wpa_printf(MSG_DEBUG, "httpread: get more (%p)", h);
return; return;
got_file: got_file:
wpa_printf(MSG_DEBUG, "httpread got file %d bytes type %d", wpa_printf(MSG_DEBUG, "httpread got file %d bytes type %d",
h->body_nbytes, h->hdr_type); h->body_nbytes, h->hdr_type);
wpa_hexdump_ascii(MSG_MSGDUMP, "httpread: body",
h->body, h->body_nbytes);
/* Null terminate for convenience of some applications */ /* Null terminate for convenience of some applications */
if (h->body) if (h->body)
h->body[h->body_nbytes] = 0; /* null terminate */ h->body[h->body_nbytes] = 0; /* null terminate */