diff --git a/src/rtty.c b/src/rtty.c index ac9ed65..23be4c3 100644 --- a/src/rtty.c +++ b/src/rtty.c @@ -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; } } diff --git a/src/rtty.h b/src/rtty.h index ca4587f..529924e 100644 --- a/src/rtty.h +++ b/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;