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

h2: ensure only one path to close

Add a flag to protect the case both the recursed lws_read()
and the outer, grandfather lws_read() don't both try to
close the wsi.
This commit is contained in:
Andy Green 2017-12-07 13:03:06 +08:00
parent 1da0197798
commit 83af0716c5
3 changed files with 13 additions and 3 deletions

View file

@ -298,12 +298,19 @@ postbody_completion:
read_ok:
/* Nothing more to do for now */
lwsl_info("%s: %p: read_ok, used %ld (len %d, state %d)\n", __func__, wsi, (long)(buf - oldbuf), (int)len, wsi->state);
lwsl_info("%s: %p: read_ok, used %ld (len %d, state %d)\n", __func__,
wsi, (long)(buf - oldbuf), (int)len, wsi->state);
return lws_ptr_diff(buf, oldbuf);
bail:
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);
/*
* h2 / h2-ws calls us recursively in lws_read()->lws_h2_parser()->
* lws_read() pattern. Make sure that only the outer lws_read() does
* the wsi close.
*/
if (!wsi->outer_will_close)
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);
return -1;
}

View file

@ -1485,9 +1485,11 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen,
break;
}
h2n->swsi->outer_will_close = 1;
n = lws_read(h2n->swsi, in - 1, inlen + 1);
h2n->swsi->outer_will_close = 0;
if (n < 0)
break;
goto fail;
inlen -= n - 1;
in += n - 1;

View file

@ -1931,6 +1931,7 @@ struct lws {
unsigned int could_have_pending:1; /* detect back-to-back writes */
unsigned int timer_active:1;
unsigned int outer_will_close:1;
#ifdef LWS_WITH_ACCESS_LOG
unsigned int access_log_pending:1;