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

ss: conmon: assert if wsi ss handle is stale

Add a way to confirm that the ss handle recovered from a ss wsi is still
valid, by walking the pt ss list and confirming it is on there before using
it with conmon.

If it isn't, it will assert.
This commit is contained in:
Andy Green 2021-08-12 11:04:27 +01:00
parent 9cd8d1f9f3
commit 387a406f07
3 changed files with 37 additions and 1 deletions

View file

@ -552,6 +552,13 @@ int lws_ss_apply_sigv4(struct lws *wsi, struct lws_ss_handle *h,
unsigned char **p, unsigned char *end);
#endif
#if defined(_DEBUG)
void
lws_ss_assert_extant(struct lws_context *cx, int tsi, struct lws_ss_handle *h);
#else
#define lws_ss_assert_extant(_a, _b, _c)
#endif
typedef int (* const secstream_protocol_connect_munge_t)(lws_ss_handle_t *h,
char *buf, size_t len, struct lws_client_connect_info *i,
union lws_ss_contemp *ct);

View file

@ -450,6 +450,9 @@ secstream_h1(struct lws *wsi, enum lws_callback_reasons reason, void *user,
lwsl_err("%s: CCE with no ss handle %s\n", __func__, lws_wsi_tag(wsi));
break;
}
lws_ss_assert_extant(wsi->a.context, wsi->tsi, h);
assert(h->policy);
#if defined(LWS_WITH_CONMON)
@ -499,6 +502,8 @@ secstream_h1(struct lws *wsi, enum lws_callback_reasons reason, void *user,
lws_sul_cancel(&h->sul_timeout);
lws_ss_assert_extant(wsi->a.context, wsi->tsi, h);
#if defined(LWS_WITH_CONMON)
lws_conmon_ss_json(h);
#endif
@ -535,12 +540,13 @@ secstream_h1(struct lws *wsi, enum lws_callback_reasons reason, void *user,
}
break;
case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP:
if (!h)
return -1;
lws_ss_assert_extant(wsi->a.context, wsi->tsi, h);
#if defined(LWS_WITH_CONMON)
lws_conmon_ss_json(h);
#endif

View file

@ -1780,3 +1780,26 @@ lws_log_prepend_ss(struct lws_log_cx *cx, void *obj, char **p, char *e)
*p += lws_snprintf(*p, lws_ptr_diff_size_t(e, (*p)), "%s: ",
lws_ss_tag(h));
}
#if defined(_DEBUG)
void
lws_ss_assert_extant(struct lws_context *cx, int tsi, struct lws_ss_handle *h)
{
struct lws_context_per_thread *pt = &cx->pt[tsi];
lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, pt->ss_owner.head) {
struct lws_ss_handle *h1 = lws_container_of(d,
struct lws_ss_handle, list);
if (h == h1)
return; /* okay */
} lws_end_foreach_dll_safe(d, d1);
/*
* The ss handle is not listed in the pt ss handle owner...
*/
assert(0);
}
#endif