mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 08:29:45 +00:00
fix possible buffer overrun in websocket uri and sync the ws.c between sofia and verto
This commit is contained in:
parent
0cc7bc8db6
commit
59e71341db
@ -1 +1 @@
|
|||||||
Sat Aug 16 01:34:24 CDT 2014
|
Tue Sep 23 20:16:55 CDT 2014
|
||||||
|
@ -475,7 +475,7 @@ int tport_ws_init_secondary(tport_t *self, int socket, int accepted,
|
|||||||
|
|
||||||
memset(&wstp->ws, 0, sizeof(wstp->ws));
|
memset(&wstp->ws, 0, sizeof(wstp->ws));
|
||||||
|
|
||||||
if (ws_init(&wstp->ws, socket, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0, 0) < 0) {
|
if (ws_init(&wstp->ws, socket, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0, 0, 0) < 0) {
|
||||||
ws_destroy(&wstp->ws);
|
ws_destroy(&wstp->ws);
|
||||||
wstp->ws_initialized = -1;
|
wstp->ws_initialized = -1;
|
||||||
return *return_reason = "WS_INIT", -1;
|
return *return_reason = "WS_INIT", -1;
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
#include "ws.h"
|
#include "ws.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
/* warning C4706: assignment within conditional expression*/
|
|
||||||
#pragma warning(disable: 4706)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
@ -269,7 +264,7 @@ int ws_handshake(wsh_t *wsh)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(wsh->buffer+bytes) = '\0';
|
*(wsh->buffer + wsh->datalen) = '\0';
|
||||||
|
|
||||||
if (strncasecmp(wsh->buffer, "GET ", 4)) {
|
if (strncasecmp(wsh->buffer, "GET ", 4)) {
|
||||||
goto err;
|
goto err;
|
||||||
@ -317,15 +312,15 @@ int ws_handshake(wsh_t *wsh)
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
|
|
||||||
snprintf(respond, sizeof(respond), "HTTP/1.1 400 Bad Request\r\n"
|
if (!wsh->stay_open) {
|
||||||
"Sec-WebSocket-Version: 13\r\n\r\n");
|
|
||||||
|
|
||||||
//printf("ERR:\n%s\n", respond);
|
snprintf(respond, sizeof(respond), "HTTP/1.1 400 Bad Request\r\n"
|
||||||
|
"Sec-WebSocket-Version: 13\r\n\r\n");
|
||||||
|
|
||||||
|
ws_raw_write(wsh, respond, strlen(respond));
|
||||||
|
|
||||||
ws_raw_write(wsh, respond, strlen(respond));
|
ws_close(wsh, WS_NONE);
|
||||||
|
}
|
||||||
ws_close(wsh, WS_NONE);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -543,7 +538,7 @@ static int establish_logical_layer(wsh_t *wsh)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block)
|
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open)
|
||||||
{
|
{
|
||||||
memset(wsh, 0, sizeof(*wsh));
|
memset(wsh, 0, sizeof(*wsh));
|
||||||
|
|
||||||
@ -551,6 +546,7 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int
|
|||||||
wsh->block = block;
|
wsh->block = block;
|
||||||
wsh->sanity = 5000;
|
wsh->sanity = 5000;
|
||||||
wsh->ssl_ctx = ssl_ctx;
|
wsh->ssl_ctx = ssl_ctx;
|
||||||
|
wsh->stay_open = stay_open;
|
||||||
|
|
||||||
if (!ssl_ctx) {
|
if (!ssl_ctx) {
|
||||||
ssl_ctx = ws_globals.ssl_ctx;
|
ssl_ctx = ws_globals.ssl_ctx;
|
||||||
|
@ -88,6 +88,7 @@ typedef struct wsh_s {
|
|||||||
int sanity;
|
int sanity;
|
||||||
int secure_established;
|
int secure_established;
|
||||||
int logical_established;
|
int logical_established;
|
||||||
|
int stay_open;
|
||||||
int x;
|
int x;
|
||||||
void *write_buffer;
|
void *write_buffer;
|
||||||
size_t write_buffer_len;
|
size_t write_buffer_len;
|
||||||
@ -101,7 +102,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block);
|
|||||||
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
|
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
|
||||||
ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
|
ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
|
||||||
ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
|
ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
|
||||||
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block);
|
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open);
|
||||||
ssize_t ws_close(wsh_t *wsh, int16_t reason);
|
ssize_t ws_close(wsh_t *wsh, int16_t reason);
|
||||||
void ws_destroy(wsh_t *wsh);
|
void ws_destroy(wsh_t *wsh);
|
||||||
void init_ssl(void);
|
void init_ssl(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user