perf: disconnect early when an invalid message was received

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2021-09-09 01:56:08 +00:00
parent f29d160176
commit c3aee13b3f
2 changed files with 16 additions and 11 deletions

View File

@@ -313,6 +313,11 @@ static int parse_msg(struct rtty *rtty)
return 0;
msgtype = buffer_pull_u8(rb);
if (msgtype > MSG_TYPE_MAX) {
log_err("invalid message type: %d\n", msgtype);
return -1;
}
buffer_pull_u16(rb);
switch (msgtype) {
@@ -360,8 +365,7 @@ static int parse_msg(struct rtty *rtty)
break;
default:
log_err("invalid message type: %d\n", msgtype);
buffer_pull(rb, NULL, msglen);
/* never to here */
break;
}
}

View File

@@ -41,15 +41,16 @@
#define RTTY_HEARTBEAT_INTEVAL 5.0
enum {
MSG_TYPE_REGISTER = 0x00,
MSG_TYPE_LOGIN = 0x01,
MSG_TYPE_LOGOUT = 0x02,
MSG_TYPE_TERMDATA = 0x03,
MSG_TYPE_WINSIZE = 0x04,
MSG_TYPE_CMD = 0x05,
MSG_TYPE_HEARTBEAT = 0x06,
MSG_TYPE_FILE = 0x07,
MSG_TYPE_WEB = 0x08
MSG_TYPE_REGISTER,
MSG_TYPE_LOGIN,
MSG_TYPE_LOGOUT,
MSG_TYPE_TERMDATA,
MSG_TYPE_WINSIZE,
MSG_TYPE_CMD,
MSG_TYPE_HEARTBEAT,
MSG_TYPE_FILE,
MSG_TYPE_WEB,
MSG_TYPE_MAX = MSG_TYPE_WEB
};
struct rtty;