diff options
author | cbdev <cb@cbcdn.com> | 2019-08-25 13:26:40 +0200 |
---|---|---|
committer | cbdev <cb@cbcdn.com> | 2019-08-25 13:26:40 +0200 |
commit | 4256eaae74f6f27167f84e2d469deaa3da3403bc (patch) | |
tree | 34183a1fb1d0579a152def9a96850805e8b002a3 | |
parent | fadc42453aca482a9db4f5c92adf58d43d87cdc7 (diff) | |
download | websocksy-4256eaae74f6f27167f84e2d469deaa3da3403bc.tar.gz websocksy-4256eaae74f6f27167f84e2d469deaa3da3403bc.tar.bz2 websocksy-4256eaae74f6f27167f84e2d469deaa3da3403bc.zip |
Fix minor bugs
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | builtins.c | 13 | ||||
-rw-r--r-- | makefile | 8 | ||||
-rw-r--r-- | plugins/backend_file.c | 6 | ||||
-rw-r--r-- | websocket.c | 14 |
5 files changed, 28 insertions, 15 deletions
@@ -154,7 +154,7 @@ To build `websocksy`, you need the following things * A working C compiler * `make` -* `gnutls` and `libnettle` development packages (`libnettle-dev` and `libgnutls28-dev` for Debian, respectively) +* `gnutls` and `libnettle` development packages (`nettle-dev` and `libgnutls28-dev` for Debian, respectively) Run `make` in the project directory to build the core binary as well as the default plugins. @@ -216,6 +216,8 @@ int64_t framing_separator(uint8_t* data, size_t length, size_t last_read, ws_ope if(!isxdigit(config->separator[u + 2]) || !isxdigit(config->separator[u + 3])){ fprintf(stderr, "Prematurely terminated hex byte sequence in separator framing function\n"); + free(config->separator); + free(config); return -1; } sscanf((char*) (config->separator + u + 3), "%02x", &hex); @@ -227,7 +229,9 @@ int64_t framing_separator(uint8_t* data, size_t length, size_t last_read, ws_ope p++; } config->length = p; - *framing_data = config; + if(framing_data){ + *framing_data = config; + } } else if(!data && config){ //free parsed configuration @@ -238,7 +242,7 @@ int64_t framing_separator(uint8_t* data, size_t length, size_t last_read, ws_ope return 0; } - if(config->length){ + if(config && config->length){ for(u = 0; u < last_read && (last_read - u) >= config->length; u++){ if(!memcmp(data + (length - last_read) + u, config->separator, config->length)){ return (length - last_read) + u + config->length; @@ -283,5 +287,10 @@ int64_t framing_newline(uint8_t* data, size_t length, size_t last_read, ws_opera bytes = framing_separator(data, length, last_read, opcode, framing_data, NULL); } + //this should never happen + if(bytes < 0){ + return length; + } + return framing_auto(data, bytes, 0, opcode, NULL, NULL); } @@ -1,10 +1,10 @@ .PHONY: all clean plugins -PLUGINPATH?=plugins/ +PLUGINPATH ?= plugins/ -CFLAGS=-g -Wall -Wpedantic -DPLUGINS=\"$(PLUGINPATH)\" -LDLIBS=-lnettle -ldl +CFLAGS += -g -Wall -Wpedantic -DPLUGINS=\"$(PLUGINPATH)\" +LDLIBS = -lnettle -ldl -OBJECTS=builtins.o network.o websocket.o plugin.o config.o +OBJECTS = builtins.o network.o websocket.o plugin.o config.o all: websocksy diff --git a/plugins/backend_file.c b/plugins/backend_file.c index 9976170..980a203 100644 --- a/plugins/backend_file.c +++ b/plugins/backend_file.c @@ -220,7 +220,11 @@ ws_peer_info query(char* endpoint, size_t protocols, char** protocol, size_t hea //read it for(line_length = getline(&line, &line_alloc, input); line_length >= 0; line_length = getline(&line, &line_alloc, input)){ memset(components, 0, sizeof(components)); - //TODO rtrim line + //rtrim line + p = strlen(line); + for(; p > 0 && !isprint(line[p]); p--){ + line[p] = 0; + } //read lines of host subproto framing framing-config components[0] = strchr(line, ' '); diff --git a/websocket.c b/websocket.c index 1fff538..f3c2631 100644 --- a/websocket.c +++ b/websocket.c @@ -13,11 +13,11 @@ #define WS_FRAME_HEADER_LEN 16 #define WS_FLAG_FIN 0x80 -#define WS_GET_FIN(a) ((a & WS_FLAG_FIN) >> 7) -#define WS_GET_RESERVED(a) ((a & 0xE0) >> 4) -#define WS_GET_OP(a) ((a & 0x0F)) -#define WS_GET_MASK(a) ((a & 0x80) >> 7) -#define WS_GET_LEN(a) ((a & 0x7F)) +#define WS_GET_FIN(a) (((a) & WS_FLAG_FIN) >> 7) +#define WS_GET_RESERVED(a) (((a) & 0xE0) >> 4) +#define WS_GET_OP(a) ((a) & 0x0F) +#define WS_GET_MASK(a) (((a) & 0x80) >> 7) +#define WS_GET_LEN(a) ((a) & 0x7F) /* * Close and shut down a WebSocket connection, including a connected @@ -165,8 +165,8 @@ static int ws_upgrade_http(websocket* ws){ sha1_update(&ws_accept_ctx, strlen(RFC6455_MAGIC_KEY), (uint8_t*) RFC6455_MAGIC_KEY); sha1_digest(&ws_accept_ctx, sizeof(ws_accept_digest), (uint8_t*) &ws_accept_digest); base64_encode_init(&ws_accept_encode); - encode_offset = base64_encode_update(&ws_accept_encode, (uint8_t*) ws_accept_key, SHA1_DIGEST_SIZE, ws_accept_digest); - encode_offset += base64_encode_final(&ws_accept_encode, (uint8_t*) ws_accept_key + encode_offset); + encode_offset = base64_encode_update(&ws_accept_encode, (char*) ws_accept_key, SHA1_DIGEST_SIZE, ws_accept_digest); + encode_offset += base64_encode_final(&ws_accept_encode, (char*) ws_accept_key + encode_offset); memcpy(ws_accept_key + encode_offset, "\r\n\0", 3); //send websocket accept key |