mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
perf: disconnect early when an invalid message was received
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
19
src/rtty.h
19
src/rtty.h
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user