[sgen] Clean exit if we can't read binprot file due to unsupported version
authorVlad Brezae <brezaevlad@gmail.com>
Thu, 29 Sep 2016 10:36:08 +0000 (13:36 +0300)
committerVlad Brezae <brezaevlad@gmail.com>
Thu, 19 Jan 2017 22:45:16 +0000 (00:45 +0200)
mono/sgen/sgen-protocol.h
tools/sgen/sgen-grep-binprot.c

index 3fe848878ec8e212ef60bf6ab411e5b3f3306706..db873fe8890b83ff8fe5e30a6aff86ad9ee813e6 100644 (file)
 #include "sgen-gc.h"
 
 #define PROTOCOL_HEADER_CHECK 0xde7ec7ab1ec0de
+/*
+ * The version needs to be bumped every time we introduce breaking changes (like
+ * adding new protocol entries or various format changes). The latest protocol grepper
+ * should be able to handle all the previous versions, while an old grepper will
+ * be able to tell if it cannot handle the format.
+ */
 #define PROTOCOL_HEADER_VERSION 1
 
 /* Special indices returned by MATCH_INDEX. */
index 4ca309f38eb6d3d8ef67ea96e4a2290bb0395b24..ef7b07f6400399ae4139455fd1a510c4012e7d02 100644 (file)
@@ -571,8 +571,13 @@ sgen_binary_protocol_read_header (EntryStream *stream)
                return FALSE;
        if (type == PROTOCOL_ID (binary_protocol_header)) {
                PROTOCOL_STRUCT (binary_protocol_header) * str = (PROTOCOL_STRUCT (binary_protocol_header) *) data;
-               if (str->check == PROTOCOL_HEADER_CHECK && str->ptr_size == BINPROT_SIZEOF_VOID_P)
+               if (str->check == PROTOCOL_HEADER_CHECK && str->ptr_size == BINPROT_SIZEOF_VOID_P) {
+                       if (str->version > PROTOCOL_HEADER_VERSION) {
+                               fprintf (stderr, "The file contains a newer version %d. We support up to %d. Please update.\n", str->version, PROTOCOL_HEADER_VERSION);
+                               exit (1);
+                       }
                        return TRUE;
+               }
        }
        return FALSE;
 #else