1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

ah: use unk_pos to clean up unknown header starts even without CUSTOM_HEADERS

This commit is contained in:
Andy Green 2020-06-26 07:34:27 +01:00
parent 8eca7e17f2
commit a75a476026
3 changed files with 6 additions and 18 deletions

View file

@ -349,9 +349,7 @@ start_ws_handshake:
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART;
wsi->http.ah->lextable_pos = 0;
#if defined(LWS_WITH_CUSTOM_HEADERS)
wsi->http.ah->unk_pos = 0;
#endif
/* If we're (re)starting on hdr, need other implied init */
wsi->http.ah->ues = URIES_IDLE;
#endif
@ -383,9 +381,7 @@ client_http_body_sent:
/* prepare ourselves to do the parsing */
wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART;
wsi->http.ah->lextable_pos = 0;
#if defined(LWS_WITH_CUSTOM_HEADERS)
wsi->http.ah->unk_pos = 0;
#endif
#endif
lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY);
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
@ -553,9 +549,7 @@ lws_http_transaction_completed_client(struct lws *wsi)
wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART;
wsi->http.ah->lextable_pos = 0;
#if defined(LWS_WITH_CUSTOM_HEADERS)
wsi->http.ah->unk_pos = 0;
#endif
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
wsi->context->timeout_secs);

View file

@ -96,8 +96,8 @@ _lws_header_table_reset(struct allocated_headers *ah)
ah->http_response = 0;
ah->parser_state = WSI_TOKEN_NAME_PART;
ah->lextable_pos = 0;
#if defined(LWS_WITH_CUSTOM_HEADERS)
ah->unk_pos = 0;
#if defined(LWS_WITH_CUSTOM_HEADERS)
ah->unk_ll_head = 0;
ah->unk_ll_tail = 0;
#endif
@ -1097,9 +1097,6 @@ swallow:
if (c >= 'A' && c <= 'Z')
c += 'a' - 'A';
#if defined(LWS_WITH_CUSTOM_HEADERS)
/*
* ...in case it's an unknown header, speculatively
* store it as the name comes in. If we recognize it as
@ -1108,6 +1105,7 @@ swallow:
if (!wsi->mux_substream && !ah->unk_pos) {
ah->unk_pos = ah->pos;
#if defined(LWS_WITH_CUSTOM_HEADERS)
/*
* Prepare new unknown header linked-list entry
*
@ -1118,8 +1116,8 @@ swallow:
for (n = 0; n < 8; n++)
if (!lws_pos_in_bounds(wsi))
ah->data[ah->pos++] = 0;
}
#endif
}
if (lws_pos_in_bounds(wsi))
return LPR_FAIL;
@ -1201,7 +1199,6 @@ nope:
/* b7 = 0, end or 3-byte */
if (lextable_h1[pos] < FAIL_CHAR) {
#if defined(LWS_WITH_CUSTOM_HEADERS)
if (!wsi->mux_substream) {
/*
* We hit a terminal marker, so
@ -1212,7 +1209,7 @@ nope:
ah->pos = ah->unk_pos;
ah->unk_pos = 0;
}
#endif
ah->lextable_pos = pos;
break;
}
@ -1390,10 +1387,7 @@ excessive:
goto forbid;
if (c == '\x0a') {
ah->parser_state = WSI_TOKEN_NAME_PART;
#if defined(LWS_WITH_CUSTOM_HEADERS)
ah->unk_pos = 0;
#endif
ah->lextable_pos = 0;
ah->unk_pos = ah->lextable_pos = 0;
} else
ah->parser_state = WSI_TOKEN_SKIPPING;
break;

View file

@ -125,9 +125,9 @@ struct allocated_headers {
ah_data_idx_t pos;
ah_data_idx_t http_response;
ah_data_idx_t current_token_limit;
ah_data_idx_t unk_pos; /* to undo speculative unknown header */
#if defined(LWS_WITH_CUSTOM_HEADERS)
ah_data_idx_t unk_pos; /* to undo speculative unknown header */
ah_data_idx_t unk_value_pos;
ah_data_idx_t unk_ll_head;