Skip to content

Commit 983e35b

Browse files
authored
Merge pull request #195 from freeswitch/ws_payload_size
Add ws_set_global_payload_size_max() API.
2 parents 4398da8 + 544989b commit 983e35b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

libsofia-sip-ua/tport/ws.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#define SHA1_HASH_SIZE 20
3131
static struct ws_globals_s ws_globals;
32+
ssize_t ws_global_payload_size_max = 0;
3233

3334
#ifndef WSS_STANDALONE
3435

@@ -712,11 +713,16 @@ int establish_logical_layer(wsh_t *wsh)
712713
return 0;
713714
}
714715

716+
void ws_set_global_payload_size_max(ssize_t bytes)
717+
{
718+
ws_global_payload_size_max = bytes;
719+
}
715720

716721
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open)
717722
{
718723
memset(wsh, 0, sizeof(*wsh));
719724

725+
wsh->payload_size_max = ws_global_payload_size_max;
720726
wsh->sock = sock;
721727
wsh->block = block;
722728
wsh->sanity = WS_INIT_SANITY;
@@ -1007,6 +1013,12 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
10071013

10081014
wsh->bbuflen = need + blen + wsh->rplen;
10091015

1016+
if (wsh->payload_size_max && wsh->bbuflen > wsh->payload_size_max) {
1017+
/* size limit */
1018+
*oc = WSOC_CLOSE;
1019+
return ws_close(wsh, WS_NONE);
1020+
}
1021+
10101022
if ((tmp = realloc(wsh->bbuffer, wsh->bbuflen))) {
10111023
wsh->bbuffer = tmp;
10121024
} else {

libsofia-sip-ua/tport/ws.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ typedef struct wsh_s {
117117
int x;
118118
void *write_buffer;
119119
size_t write_buffer_len;
120+
121+
ssize_t payload_size_max;
120122
} wsh_t;
121123

122124
ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
@@ -127,6 +129,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block);
127129
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
128130
ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
129131
ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
132+
void ws_set_global_payload_size_max(ssize_t bytes);
130133
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open);
131134
ssize_t ws_close(wsh_t *wsh, int16_t reason);
132135
void ws_destroy(wsh_t *wsh);

0 commit comments

Comments
 (0)