Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
[htparse] fix up some stuff to make coverity happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Ellzey committed Apr 20, 2016
1 parent 5c254d3 commit abc7eb4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions htparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ struct htparser {

void * userdata;

unsigned int buf_idx;
size_t buf_idx;
/* Must be last since htparser_init memsets up to the offset of this buffer */
char buf[PARSER_STACK_MAX];
};

static uint32_t usual[] = {
static uint32_t usual[] = {
0xffffdbfe,
0x7fff37d6,
0xffffffff,
Expand All @@ -151,7 +151,7 @@ static uint32_t usual[] = {
0xffffffff
};

static int8_t unhex[256] = {
static int8_t unhex[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Expand Down Expand Up @@ -623,7 +623,7 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)

htparse_log_debug("[%p] data[%d] = %c (%x)", p, i, isprint(ch) ? ch : ' ', ch);

if (p->buf_idx >= sizeof(p->buf)) {
if (p->buf_idx >= PARSER_STACK_MAX) {
p->error = htparse_error_too_big;
return i + 1;
}
Expand Down Expand Up @@ -1020,12 +1020,16 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
res = 0;

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
p->buf[p->buf_idx++] = ch;
p->buf[p->buf_idx] = '\0';
p->state = s_check_uri;
if (lz_likely(buf_idx + 1) < PARSER_STACK_MAX) {
p->buf[p->buf_idx++] = ch;
p->buf[p->buf_idx] = '\0';
p->state = s_check_uri;
}
break;
}

break;

switch (ch) {
case ' ':
{
Expand Down Expand Up @@ -1814,14 +1818,14 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)

switch (ch) {
case LF:
res = 0;
res = hook_on_hdrs_complete_run(p, hooks);

if (res) {
if (res != 0) {
p->error = htparse_error_user;
return i + 1;
}


p->buf_idx = 0;
htparse_log_debug("[%p] HERE", p);

Expand All @@ -1839,17 +1843,18 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
p->state = s_hdrline_done;
}

if (res) {
if (res != 0) {
p->error = htparse_error_user;
return i + 1;
}
break;

default:
p->error = htparse_error_inval_hdr;
return i + 1;
} /* switch */

if (res) {
if (res != 0) {
p->error = htparse_error_user;
return i + 1;
}
Expand Down

0 comments on commit abc7eb4

Please sign in to comment.