remove lws_ensure_user_space from public api change return
The function has a logical problem when the size of the requested allocation is 0, it will return NULL which is overloaded as failure. Actually the whole function is evil as an api, this patch moves it out of the public API space and fixes it to return 0 for success or 1 for fail. Private code does not need to to return wsi->user_space and public code should only get that from the callback as discussed on trac recently. Thanks to Edwin for debugging the problem. Reported-by: Edwin van den Oetelaar <oetelaar.automatisering@gmail.com> Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
cb8febdda2
commit
2af4d5b2e2
7 changed files with 10 additions and 27 deletions
|
@ -596,8 +596,7 @@ check_accept:
|
|||
}
|
||||
|
||||
/* allocate the per-connection user memory (if any) */
|
||||
if (wsi->protocol->per_session_data_size &&
|
||||
!libwebsocket_ensure_user_space(wsi)) {
|
||||
if (libwebsocket_ensure_user_space(wsi)) {
|
||||
lwsl_err("Problem allocating wsi user mem\n");
|
||||
goto bail2;
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ libwebsocket_read(struct libwebsocket_context *context,
|
|||
lwsl_info("HTTP request for '%s'\n",
|
||||
lws_hdr_simple_ptr(wsi, WSI_TOKEN_GET_URI));
|
||||
|
||||
if (libwebsocket_ensure_user_space(wsi) == NULL) {
|
||||
if (libwebsocket_ensure_user_space(wsi)) {
|
||||
/* drop the header info */
|
||||
if (wsi->u.hdr.ah)
|
||||
free(wsi->u.hdr.ah);
|
||||
|
|
|
@ -2154,16 +2154,11 @@ libwebsocket_get_reserved_bits(struct libwebsocket *wsi)
|
|||
return wsi->u.ws.rsv;
|
||||
}
|
||||
|
||||
/**
|
||||
* libwebsocket_ensure_user_space(): return the user context for the connection if possible
|
||||
* @wsi: websocket connection instance
|
||||
*/
|
||||
|
||||
void *
|
||||
int
|
||||
libwebsocket_ensure_user_space(struct libwebsocket *wsi)
|
||||
{
|
||||
if (!wsi->protocol)
|
||||
return NULL;
|
||||
return 1;
|
||||
|
||||
/* allocate the per-connection user memory (if any) */
|
||||
|
||||
|
@ -2172,12 +2167,12 @@ libwebsocket_ensure_user_space(struct libwebsocket *wsi)
|
|||
wsi->protocol->per_session_data_size);
|
||||
if (wsi->user_space == NULL) {
|
||||
lwsl_err("Out of memory for conn user space\n");
|
||||
return NULL;
|
||||
return 1;
|
||||
}
|
||||
memset(wsi->user_space, 0,
|
||||
wsi->protocol->per_session_data_size);
|
||||
}
|
||||
return wsi->user_space;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void lwsl_emit_stderr(int level, const char *line)
|
||||
|
|
|
@ -880,9 +880,6 @@ libwebsocket_is_final_fragment(struct libwebsocket *wsi);
|
|||
LWS_EXTERN unsigned char
|
||||
libwebsocket_get_reserved_bits(struct libwebsocket *wsi);
|
||||
|
||||
LWS_EXTERN void *
|
||||
libwebsocket_ensure_user_space(struct libwebsocket *wsi);
|
||||
|
||||
LWS_EXTERN int
|
||||
libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable);
|
||||
|
||||
|
|
|
@ -508,6 +508,9 @@ LWS_EXTERN int
|
|||
lws_hdr_simple_create(struct libwebsocket *wsi,
|
||||
enum lws_token_indexes h, const char *s);
|
||||
|
||||
LWS_EXTERN int
|
||||
libwebsocket_ensure_user_space(struct libwebsocket *wsi);
|
||||
|
||||
#ifndef LWS_NO_SERVER
|
||||
LWS_EXTERN int handshake_0405(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
|
|
|
@ -75,8 +75,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
|
|||
}
|
||||
|
||||
/* allocate the per-connection user memory (if any) */
|
||||
if (wsi->protocol->per_session_data_size &&
|
||||
!libwebsocket_ensure_user_space(wsi))
|
||||
if (libwebsocket_ensure_user_space(wsi))
|
||||
goto bail;
|
||||
|
||||
/* create the response packet */
|
||||
|
|
|
@ -382,16 +382,6 @@ Some apis can act on all live connections of a given protocol,
|
|||
this is how you can get a pointer to the active protocol if needed.
|
||||
</blockquote>
|
||||
<hr>
|
||||
<h2>libwebsocket_ensure_user_space - </h2>
|
||||
<i>void *</i>
|
||||
<b>libwebsocket_ensure_user_space</b>
|
||||
(<i>struct libwebsocket *</i> <b>wsi</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>wsi</b>
|
||||
<dd>websocket connection instance
|
||||
</dl>
|
||||
<hr>
|
||||
<h2>lws_set_log_level - Set the logging bitfield</h2>
|
||||
<i>void</i>
|
||||
<b>lws_set_log_level</b>
|
||||
|
|
Loading…
Add table
Reference in a new issue