mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-18 13:14:34 +00:00
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
- CodeChange: added str_validate(char *str) function that checks if a string contains only printable characters and if not, replaces those characters by question marks. Also move IsValidAsciiChar() to string.h
This commit is contained in:
parent
8f873d4ece
commit
0f41b99c5e
10
macros.h
10
macros.h
@ -164,14 +164,4 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
|
||||
*/
|
||||
#define ALIGN(x, n) (((x) + (n) - 1) & ~((n) - 1))
|
||||
|
||||
/* IS_INT_INSIDE = filter for ascii-function codes like BELL and so on [we need an special filter here later] */
|
||||
static inline bool IsValidAsciiChar(byte key)
|
||||
{
|
||||
// XXX This filter stops certain crashes, but may be too restrictive.
|
||||
return IS_INT_INSIDE(key, ' ', 127) ||
|
||||
(IS_INT_INSIDE(key, 160, 256) &&
|
||||
key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF &&
|
||||
key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9);
|
||||
}
|
||||
|
||||
#endif /* MACROS_H */
|
||||
|
@ -179,16 +179,12 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||
DrawString(260, y, STR_NETWORK_CLIENTS, 2); // clients on the server / maximum slots
|
||||
y += 10;
|
||||
|
||||
if (sel->info.server_lang < NETWORK_NUM_LANGUAGES) {
|
||||
SetDParam(0, STR_NETWORK_LANG_ANY + sel->info.server_lang);
|
||||
DrawString(260, y, STR_NETWORK_LANGUAGE, 2); // server language
|
||||
}
|
||||
SetDParam(0, STR_NETWORK_LANG_ANY + sel->info.server_lang);
|
||||
DrawString(260, y, STR_NETWORK_LANGUAGE, 2); // server language
|
||||
y += 10;
|
||||
|
||||
if (sel->info.map_set < NUM_LANDSCAPE ) {
|
||||
SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
|
||||
DrawString(260, y, STR_NETWORK_TILESET, 2); // tileset
|
||||
}
|
||||
SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
|
||||
DrawString(260, y, STR_NETWORK_TILESET, 2); // tileset
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, sel->info.map_width);
|
||||
@ -231,7 +227,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||
|
||||
case WE_CLICK:
|
||||
_selected_field = e->click.widget;
|
||||
switch(e->click.widget) {
|
||||
switch (e->click.widget) {
|
||||
case 0: case 14: /* Close 'X' | Cancel button */
|
||||
DeleteWindowById(WC_NETWORK_WINDOW, 0);
|
||||
break;
|
||||
|
@ -119,6 +119,12 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
|
||||
item->info.map_set = NetworkRecv_uint8(&_udp_cs, p);
|
||||
item->info.dedicated = NetworkRecv_uint8(&_udp_cs, p);
|
||||
|
||||
str_validate(item->info.server_name);
|
||||
str_validate(item->info.server_revision);
|
||||
str_validate(item->info.map_name);
|
||||
if (item->info.server_lang >= NETWORK_NUM_LANGUAGES) item->info.server_lang = 0;
|
||||
if (item->info.map_set >= NUM_LANDSCAPE ) item->info.map_set = 0;
|
||||
|
||||
if (item->info.hostname[0] == '\0')
|
||||
snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr));
|
||||
}
|
||||
|
6
string.c
6
string.c
@ -57,3 +57,9 @@ char* CDECL str_fmt(const char* str, ...)
|
||||
if (p != NULL) memcpy(p, buf, len + 1);
|
||||
return p;
|
||||
}
|
||||
|
||||
void str_validate(char *str)
|
||||
{
|
||||
for (; *str != '\0'; str++)
|
||||
if (!IsValidAsciiChar(*str)) *str = '?';
|
||||
}
|
||||
|
16
string.h
16
string.h
@ -25,4 +25,20 @@ char* strecpy(char* dst, const char* src, const char* last);
|
||||
|
||||
char* CDECL str_fmt(const char* str, ...);
|
||||
|
||||
/** Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?' */
|
||||
void str_validate(char *str);
|
||||
|
||||
/** Only allow valid ascii-function codes. Filter special codes like BELL and
|
||||
* so on [we need a special filter here later]
|
||||
* @param key character to be checked
|
||||
* @return true or false depending if the character is printable/valid or not */
|
||||
static inline bool IsValidAsciiChar(byte key)
|
||||
{
|
||||
// XXX This filter stops certain crashes, but may be too restrictive.
|
||||
return (key >= ' ' && key < 127) || (key >= 160 &&
|
||||
key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF &&
|
||||
key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9);
|
||||
}
|
||||
|
||||
#endif /* STRING_H */
|
||||
|
Loading…
Reference in New Issue
Block a user