Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash #1450

Merged
merged 9 commits into from
Oct 9, 2020
Merged

Fix crash #1450

merged 9 commits into from
Oct 9, 2020

Conversation

avbelov23
Copy link
Contributor

@avbelov23 avbelov23 commented Sep 21, 2020

fix #1408

  • copying each header to the cache, we must leave space for the string header, also, if there are duplicate headers, then we must write the duplicate header.

Earlier in the presence of duplicates, there was a double shift at the beginning of the copying procedure:
CSTR_MOVE_HDR
CSTR_WRITE_HDR
CSTR_MOVE_HDR
CSTR_MOVE_HDR

CSTR_WRITE_HDR

  • eliminated the progressive accumulation of duplicate lengths

  • some fixes for rebalancing procedure

  • if hpack rb-tree node was deleted, then we look for a new place to add a node, because the old place may be invalid due to the reducing of the procedure for deleting a node with two children to deleting a node with less than two children

@@ -996,7 +996,7 @@ __tfw_cache_strcpy(char **p, TdbVRec **trec, TfwStr *src, size_t tot_len,
{
long copied = 0;

while (copied < src->len) {
while (copied < src->len && tot_len - copied) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition is strange and masks issue root. Why a new string to be copied to cache could be bigger than response length in total? This is the question that needs to be fixed.

This workaround messes up the cache entry and the response is never cached and always forwarded from origin.

@@ -1418,7 +1418,7 @@ tfw_h2_msg_rewrite_data(TfwHttpTransIter *mit, const TfwStr *str,
return -E2BIG;
}

memcpy_fast(mit->curr_ptr, c->data + c_off, n_copy);
tfw_cstrtolower(mit->curr_ptr, c->data + c_off, n_copy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change not only header names are converted to lowercase, but also header values. Such behaviour in unacceptable and harmful.

header, also, if there are duplicate headers, then we must write the
duplicate header.

earlier in the presence of duplicates, there was a double shift at the
beginning of the copying procedure
CSTR_MOVE_HDR
CSTR_WRITE_HDR
*CSTR_MOVE_HDR*
*CSTR_MOVE_HDR*
CSTR_WRITE_HDR
at each iteration in the loop above, there is already accumulation of
duplicate lengths in dc_iter.acc_len
Copy link
Contributor

@vankoven vankoven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now.

}
*acc_len += dc_iter.acc_len;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor

@vankoven vankoven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately all the tests from test_hpack.c has passed on this branch without any change. I say unfortunately because we has the issues with hpack encoding and the PR fixes them while all the tests are green in both cases. Thus the tests must be extended to catch the issue.

* deleting a node with less than two children.
*/
if (was_del) {
res = tfw_hpack_rbtree_find(tbl, hdr, &node, place);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, there is a case, when place can become invalid, but the proposed change is expensive: it possibly involves a lot of string compare operations. It seems that tfw_hpack_rbtree_erase() should be updated to keep place valid.

otherwise, at the next iteration, a mismatch occurs
otherwise, at the next iteration, a mismatch occurs
because the old place may be invalid due to the reducing of the
procedure for deleting a node with two children to deleting a node
with less than two children
Copy link
Contributor

@vankoven vankoven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@avbelov23 avbelov23 merged commit 4ffa482 into master Oct 9, 2020
@avbelov23 avbelov23 deleted the avb-1408 branch October 9, 2020 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on converting mixed headers from h1 to h2
2 participants