From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 17 Aug 2018 13:14:10 +0300 From: Vladimir Davydov Subject: Re: [PATCH v1 1/1] xlog: fix out of static memory on metadata load Message-ID: <20180817101410.zomayvmosk5cp33j@esperanza> References: <217089583da1d608c61d1c4a106fee07d43332f9.1534336273.git.kshcherbatov@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <217089583da1d608c61d1c4a106fee07d43332f9.1534336273.git.kshcherbatov@tarantool.org> To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org List-ID: On Wed, Aug 15, 2018 at 03:32:02PM +0300, Kirill Shcherbatov wrote: > This problem triggered asan checks on start tarantool > with existent xlog. We don't have to touch even static > non-initialized memory. > --- > Branch: http://github.com/tarantool/tarantool/tree/kshch/vinyl-xlog-out-of-static-memory > > src/box/xlog.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/src/box/xlog.c b/src/box/xlog.c > index 5ed11fc..797f153 100644 > --- a/src/box/xlog.c > +++ b/src/box/xlog.c > @@ -261,8 +261,11 @@ xlog_meta_parse(struct xlog_meta *meta, const char **data, > assert(val <= val_end); > pos = eol + 1; > > - if (memcmp(key, INSTANCE_UUID_KEY, key_end - key) == 0 || > - memcmp(key, INSTANCE_UUID_KEY_V12, key_end - key) == 0) { > + size_t len = key_end - key; > + if ((len == strlen(INSTANCE_UUID_KEY) && > + memcmp(key, INSTANCE_UUID_KEY, len) == 0) || > + (len == strlen(INSTANCE_UUID_KEY_V12) && > + memcmp(key, INSTANCE_UUID_KEY_V12, key_end - key) == 0)) { Too much of code duplication. Please add a helper for key matching. > /* > * Instance: > */ > @@ -277,19 +280,22 @@ xlog_meta_parse(struct xlog_meta *meta, const char **data, > diag_set(XlogError, "can't parse instance UUID"); > return -1; > } > - } else if (memcmp(key, VCLOCK_KEY, key_end - key) == 0){ > + } else if (len == strlen(VCLOCK_KEY) && > + memcmp(key, VCLOCK_KEY, len) == 0) { > /* > * VClock: > */ > if (parse_vclock(val, val_end, &meta->vclock) != 0) > return -1; > - } else if (memcmp(key, PREV_VCLOCK_KEY, key_end - key) == 0) { > + } else if (len == strlen(PREV_VCLOCK_KEY) && > + memcmp(key, PREV_VCLOCK_KEY, len) == 0) { > /* > * PrevVClock: > */ > if (parse_vclock(val, val_end, &meta->prev_vclock) != 0) > return -1; > - } else if (memcmp(key, VERSION_KEY, key_end - key) == 0) { > + } else if (len == strlen(VERSION_KEY) && > + memcmp(key, VERSION_KEY, len) == 0) { > /* Ignore Version: for now */ > } else { > /*