Skip to main content
Sign in
Snippets Groups Projects
Commit acbaee64 authored by Andy Green's avatar Andy Green
Browse files

add lws_confirm_legit_wsi

parent a1ce6be9
Branches
Tags
No related merge requests found
...@@ -2117,6 +2117,38 @@ libwebsocket_ensure_user_space(struct libwebsocket *wsi) ...@@ -2117,6 +2117,38 @@ libwebsocket_ensure_user_space(struct libwebsocket *wsi)
return wsi->user_space; return wsi->user_space;
} }
/**
* lws_confirm_legit_wsi: returns nonzero if the wsi looks bad
*
* @wsi: struct libwebsocket to assess
*
* Performs consistecy checks on what the wsi claims and what the
* polling arrays hold. This'll catch a closed wsi still in use.
* Don't try to use on the listen (nonconnection) wsi as it will
* fail it. Otherwise 0 return == wsi seems consistent.
*/
int lws_confirm_legit_wsi(struct libwebsocket *wsi)
{
struct libwebsocket_context *context;
if (!(wsi && wsi->protocol && wsi->protocol->owning_server))
return 1;
context = wsi->protocol->owning_server;
if (!context)
return 2;
if (!wsi->position_in_fds_table)
return 3; /* position in fds table looks bad */
if (context->fds[wsi->position_in_fds_table].fd != wsi->sock)
return 4; /* pollfd entry does not wait on our socket descriptor */
if (context->lws_lookup[wsi->sock] != wsi)
return 5; /* lookup table does not agree with wsi */
return 0;
}
static void lwsl_emit_stderr(const char *line) static void lwsl_emit_stderr(const char *line)
{ {
... ...
......
...@@ -295,6 +295,10 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, ...@@ -295,6 +295,10 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
struct lws_tokens eff_buf; struct lws_tokens eff_buf;
int m; int m;
if (lws_confirm_legit_wsi(wsi)) {
lwsl_err("libwebsocket_write on illegitimate wsi\n");
return -1;
}
if (len == 0 && protocol != LWS_WRITE_CLOSE) { if (len == 0 && protocol != LWS_WRITE_CLOSE) {
lwsl_warn("zero length libwebsocket_write attempt\n"); lwsl_warn("zero length libwebsocket_write attempt\n");
return 0; return 0;
... ...
......
...@@ -491,6 +491,9 @@ lws_issue_raw_ext_access(struct libwebsocket *wsi, ...@@ -491,6 +491,9 @@ lws_issue_raw_ext_access(struct libwebsocket *wsi,
extern int extern int
_libwebsocket_rx_flow_control(struct libwebsocket *wsi); _libwebsocket_rx_flow_control(struct libwebsocket *wsi);
extern int
lws_confirm_legit_wsi(struct libwebsocket *wsi);
extern int extern int
user_callback_handle_rxflow(callback_function, struct libwebsocket_context * context, user_callback_handle_rxflow(callback_function, struct libwebsocket_context * context,
struct libwebsocket *wsi, struct libwebsocket *wsi,
... ...
......
...@@ -350,6 +350,23 @@ having to take any care about data visibility between the processes, it'll ...@@ -350,6 +350,23 @@ having to take any care about data visibility between the processes, it'll
"just work". "just work".
</blockquote> </blockquote>
<hr> <hr>
<h2>lws_confirm_legit_wsi - </h2>
<i>int</i>
<b>lws_confirm_legit_wsi</b>
(<i>struct libwebsocket *</i> <b>wsi</b>)
<h3>Arguments</h3>
<dl>
<dt><b>wsi</b>
<dd>struct libwebsocket to assess
</dl>
<h3>Description</h3>
<blockquote>
Performs consistecy checks on what the wsi claims and what the
polling arrays hold. This'll catch a closed wsi still in use.
Don't try to use on the listen (nonconnection) wsi as it will
fail it. Otherwise 0 return == wsi seems consistent.
</blockquote>
<hr>
<h2>lws_set_log_level - Set the logging bitfield</h2> <h2>lws_set_log_level - Set the logging bitfield</h2>
<i>void</i> <i>void</i>
<b>lws_set_log_level</b> <b>lws_set_log_level</b>
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment