summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-01-16 22:56:18 +0000
committerrubidium <rubidium@openttd.org>2007-01-16 22:56:18 +0000
commit96b19ca23e95b7b2a05adca53774254f42a76504 (patch)
treed7311352ca40e4266a7c35d38d7432eb466a2ad9
parentf19b87df08347bd1f6e0c6f778a0f7fc053516e1 (diff)
downloadopenttd-96b19ca23e95b7b2a05adca53774254f42a76504.tar.xz
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
-rw-r--r--src/network/network_client.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 47bb952f2..016529889 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -468,10 +468,19 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
_frame_counter = _frame_counter_server = _frame_counter_max = NetworkRecv_uint32(MY_CLIENT, p);
- _network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
_network_join_kbytes = 0;
_network_join_kbytes_total = NetworkRecv_uint32(MY_CLIENT, p) / 1024;
- InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
+
+ /* If the network connection has been closed due to loss of connection
+ * or when _network_join_kbytes_total is 0, the join status window will
+ * do a division by zero. When the connection is lost, we just return
+ * that. If kbytes_total is 0, the packet must be malformed as a
+ * savegame less than 1 kilobyte is practically impossible. */
+ if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
+ if (_network_join_kbytes_total == 0) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+
+ _network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
+ InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
// The first packet does not contain any more data
return NETWORK_RECV_STATUS_OKAY;