From a5ec9bad650e3e15e6016c6b53a70fada3c46919 Mon Sep 17 00:00:00 2001 From: Liu Dongmiao Date: Fri, 12 Apr 2024 07:17:06 +0800 Subject: [PATCH] both: don't send udp 0 over wss --- common.c | 4 ++++ wss-proxy-client.c | 4 ++++ wss-proxy-server.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/common.c b/common.c index 3585719..4d99f7a 100644 --- a/common.c +++ b/common.c @@ -600,6 +600,10 @@ static void raw_forward_cb(struct bufferevent *raw, void *wss) { } total_size -= UDP_FRAME_LENGTH_SIZE; payload_size = htons(payload_size); + if (payload_size == 0) { + LOGW("payload size is 0"); + continue; + } } size = evbuffer_remove(src, wss_frame_data.buffer, payload_size); if (size <= 0) { diff --git a/wss-proxy-client.c b/wss-proxy-client.c index bb91419..23d984b 100644 --- a/wss-proxy-client.c +++ b/wss-proxy-client.c @@ -474,6 +474,10 @@ static void udp_read_cb_server(evutil_socket_t sock, short event, void *ctx) { if ((size = udp_read(sock, &udp_frame, key.sockaddr, &(key.socklen))) < 0) { break; } + if (size == 0) { + LOGW("udp read empty from %d", get_port(key.sockaddr)); + continue; + } if ((data = init_udp_server(&key, context, sock, get_port(key.sockaddr))) == NULL) { break; } diff --git a/wss-proxy-server.c b/wss-proxy-server.c index b74d27a..0aaaebe 100644 --- a/wss-proxy-server.c +++ b/wss-proxy-server.c @@ -124,6 +124,10 @@ static void udp_read_cb_client(evutil_socket_t sock, short event, void *ctx) { if ((size = udp_read(sock, &udp_frame, (struct sockaddr *) &sockaddr, &socklen)) < 0) { break; } + if (size == 0) { + LOGW("udp read empty from %d", get_port((const struct sockaddr *) &sockaddr)); + continue; + } evbuffer_add(raw->input, &udp_frame, size + UDP_FRAME_LENGTH_SIZE); event_add(&(raw->ev_read), &one_minute); }