From 8e72650298f6d8f2bd2740d92bbdbda02a789cf3 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Thu, 29 Sep 2016 13:36:08 +0300 Subject: [PATCH] [sgen] Clean exit if we can't read binprot file due to unsupported version --- mono/sgen/sgen-protocol.h | 6 ++++++ tools/sgen/sgen-grep-binprot.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mono/sgen/sgen-protocol.h b/mono/sgen/sgen-protocol.h index 3fe848878ec..db873fe8890 100644 --- a/mono/sgen/sgen-protocol.h +++ b/mono/sgen/sgen-protocol.h @@ -15,6 +15,12 @@ #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. */ diff --git a/tools/sgen/sgen-grep-binprot.c b/tools/sgen/sgen-grep-binprot.c index 4ca309f38eb..ef7b07f6400 100644 --- a/tools/sgen/sgen-grep-binprot.c +++ b/tools/sgen/sgen-grep-binprot.c @@ -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 -- 2.25.1