]> git.lizzy.rs Git - minetest.git/commitdiff
Fix a crash (assert) when client set serial version < 24 in INIT
authorLoic Blot <loic.blot@unix-experience.fr>
Mon, 26 Jan 2015 14:52:02 +0000 (15:52 +0100)
committerKahrl <kahrl@gmx.net>
Tue, 27 Jan 2015 15:55:25 +0000 (16:55 +0100)
When SER_FMT_VER_LOWEST is set to zero, then the test is stupid in INIT because all client works. In mapblock we check if client's serialization version is < 24, but if client sent serialization version < 24 (15 for example) the server set it and tried to send nodes, then BOOM

To resolve the problem:
* Create a different CLIENT_MIN_VERSION to handle this problem
* Remove the exception
* Use an assert in case of bad developer code

src/mapblock.cpp
src/mapblock.h
src/serialization.h
src/server.cpp

index 4cc0abc8176104c5a5a922205d6067de223e7df2..ecd9a016b45d1d6fc010a699033cfce4b836c4b7 100644 (file)
@@ -526,11 +526,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk)
                throw SerializationError("ERROR: Not writing dummy block.");
        }
 
-       // Can't do this anymore; we have 16-bit dynamically allocated node IDs
-       // in memory; conversion just won't work in this direction.
-       if(version < 24)
-               throw SerializationError("MapBlock::serialize: serialization to "
-                               "version < 24 not possible");
+       assert(version >= SER_FMT_CLIENT_VER_LOWEST);
 
        // First byte
        u8 flags = 0;
index 5cf2bc801260504a3e7634327c7816770143f7e7..e7d7798b87a14bb6c9676272eb7253bb05cda774 100644 (file)
@@ -494,6 +494,7 @@ class MapBlock /*: public NodeContainer*/
        
        // These don't write or read version by itself
        // Set disk to true for on-disk format, false for over-the-network format
+       // Precondition: version >= SER_FMT_CLIENT_VER_LOWEST
        void serialize(std::ostream &os, u8 version, bool disk);
        // If disk == true: In addition to doing other things, will add
        // unknown blocks from id-name mapping to wndef
index caa1a66da058b0483ccd6fb19a1175f94309e194..ab6fe0f791201ed19392e1b124eea8ec70474f5d 100644 (file)
@@ -71,6 +71,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define SER_FMT_VER_HIGHEST_WRITE 25
 // Lowest supported serialization version
 #define SER_FMT_VER_LOWEST 0
+// Lowest client supported serialization version
+// Can't do < 24 anymore; we have 16-bit dynamically allocated node IDs
+// in memory; conversion just won't work in this direction.
+#define SER_FMT_CLIENT_VER_LOWEST 24
 
 inline bool ser_ver_supported(s32 v) {
        return v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST_READ;
index 2b5fe9b08297b8fba61b005599276042e496561a..31b5041ed550c278cd9c3e630c010101fe40522a 100644 (file)
@@ -1366,7 +1366,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                // Use the highest version supported by both
                int deployed = std::min(client_max, our_max);
                // If it's lower than the lowest supported, give up.
-               if(deployed < SER_FMT_VER_LOWEST)
+               if(deployed < SER_FMT_CLIENT_VER_LOWEST)
                        deployed = SER_FMT_VER_INVALID;
 
                if(deployed == SER_FMT_VER_INVALID)