wsockd: Initialise ws_frame_hdr_t before using it

Outgoing messages have uninitialised data from the stack in the 3 reserved
bits of the opcode_rsv_fin value.
This commit is contained in:
Simon Arlott 2017-07-29 19:59:20 +01:00
parent a940f54623
commit 23e722ea21
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24

View file

@ -106,6 +106,8 @@ typedef struct {
uint8_t payload_length_mask; // payload_length: 7, mask: 1 uint8_t payload_length_mask; // payload_length: 7, mask: 1
} ws_frame_hdr_t; } ws_frame_hdr_t;
#define WEBSOCKET_FRAME_HDR_INIT ((ws_frame_hdr_t) { 0, 0 })
typedef struct { typedef struct {
ws_frame_hdr_t header; ws_frame_hdr_t header;
uint8_t payload_data[WEBSOCKET_MAX_UNEXTENDED_PAYLOAD_DATA_LENGTH]; uint8_t payload_data[WEBSOCKET_MAX_UNEXTENDED_PAYLOAD_DATA_LENGTH];
@ -120,6 +122,8 @@ typedef struct {
uint16_t payload_length_extended; uint16_t payload_length_extended;
} ws_frame_ext_t; } ws_frame_ext_t;
#define WEBSOCKET_FRAME_EXT_INIT ((ws_frame_ext_t) { WEBSOCKET_FRAME_HDR_INIT, 0 })
typedef struct { typedef struct {
ws_frame_hdr_t header; ws_frame_hdr_t header;
uint64_t payload_length_extended; uint64_t payload_length_extended;
@ -327,7 +331,7 @@ conn_mod_write(conn_t * conn, void *data, size_t len)
static void static void
conn_mod_write_short_frame(conn_t * conn, void *data, int len) conn_mod_write_short_frame(conn_t * conn, void *data, int len)
{ {
ws_frame_hdr_t hdr; ws_frame_hdr_t hdr = WEBSOCKET_FRAME_HDR_INIT;
ws_frame_set_opcode(&hdr, WEBSOCKET_OPCODE_TEXT_FRAME); ws_frame_set_opcode(&hdr, WEBSOCKET_OPCODE_TEXT_FRAME);
ws_frame_set_fin(&hdr, 1); ws_frame_set_fin(&hdr, 1);
@ -341,7 +345,7 @@ conn_mod_write_short_frame(conn_t * conn, void *data, int len)
static void static void
conn_mod_write_long_frame(conn_t * conn, void *data, int len) conn_mod_write_long_frame(conn_t * conn, void *data, int len)
{ {
ws_frame_ext_t hdr; ws_frame_ext_t hdr = WEBSOCKET_FRAME_EXT_INIT;
ws_frame_set_opcode(&hdr.header, WEBSOCKET_OPCODE_TEXT_FRAME); ws_frame_set_opcode(&hdr.header, WEBSOCKET_OPCODE_TEXT_FRAME);
ws_frame_set_fin(&hdr.header, 1); ws_frame_set_fin(&hdr.header, 1);