From f1615122cad899d3cb4705a00f2a2933e712dbad Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 9 Jun 2013 23:06:53 +0000 Subject: [PATCH] Compute message_length limit automatically --- main/multi.c | 12 ++++++------ main/multi.h | 4 +--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/main/multi.c b/main/multi.c index e77199c2e..17e35d31d 100644 --- a/main/multi.c +++ b/main/multi.c @@ -870,7 +870,7 @@ multi_send_data(unsigned char *buf, int len, int priority) { if (len != message_length[(int)buf[0]]) Error("multi_send_data: Packet type %i length: %i, expected: %i\n", buf[0], len, message_length[(int)buf[0]]); - if (buf[0] > MULTI_MAX_TYPE) + if (buf[0] >= sizeof(message_length) / sizeof(message_length[0])) Error("multi_send_data: Illegal packet type %i\n", buf[0]); if (Game_mode & GM_NETWORK) @@ -893,7 +893,7 @@ void multi_send_data_direct(const ubyte *buf, int len, int pnum, int priority) { if (len != message_length[(int)buf[0]]) Error("multi_send_data_direct: Packet type %i length: %i, expected: %i\n", buf[0], len, message_length[(int)buf[0]]); - if (buf[0] > MULTI_MAX_TYPE) + if (buf[0] >= sizeof(message_length) / sizeof(message_length[0])) Error("multi_send_data_direct: Illegal packet type %i\n", buf[0]); if (pnum < 0 || pnum > MAX_PLAYERS) Error("multi_send_data_direct: Illegal player num: %i\n", pnum); @@ -2277,17 +2277,17 @@ void multi_reset_object_texture (object *objp) } void -multi_process_bigdata(const ubyte *buf, int len) +multi_process_bigdata(const ubyte *buf, unsigned len) { // Takes a bunch of messages, check them for validity, // and pass them to multi_process_data. - int type, sub_len, bytes_processed = 0; + unsigned type, sub_len, bytes_processed = 0; while( bytes_processed < len ) { type = buf[bytes_processed]; - if ( (type<0) || (type>MULTI_MAX_TYPE)) { + if ( (type>= sizeof(message_length)/sizeof(message_length[0]))) { con_printf( CON_DEBUG,"multi_process_bigdata: Invalid packet type %d!\n", type ); return; } @@ -3745,7 +3745,7 @@ multi_process_data(const ubyte *buf, int len) type = buf[0]; - if (type > MULTI_MAX_TYPE) + if (type >= sizeof(message_length) / sizeof(message_length[0])) { Int3(); return; diff --git a/main/multi.h b/main/multi.h index abcd6fd10..cfd48a1fd 100644 --- a/main/multi.h +++ b/main/multi.h @@ -115,8 +115,6 @@ extern int multi_protocol; // set and determinate used protocol #define MULTI_KILL_CLIENT 44 #define MULTI_RANK 45 -#define MULTI_MAX_TYPE 45 - #define MAX_MULTI_MESSAGE_LEN 90 //didn't change it, just moved it up #define MAX_NET_CREATE_OBJECTS 20 @@ -223,7 +221,7 @@ int multi_endlevel_poll2( newmenu *menu, d_event *event, void *userdata ); void multi_send_endlevel_packet(); void multi_leave_game(void); void multi_process_data(const ubyte *dat, int len); -void multi_process_bigdata(const ubyte *buf, int len); +void multi_process_bigdata(const ubyte *buf, unsigned len); void multi_do_death(int objnum); void multi_send_message_dialog(void); int multi_delete_extra_objects(void);