From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Subject: Re: [tarantool-patches] Re: [PATCH v1 1/1] xlog: fix out of static memory on metadata load References: <217089583da1d608c61d1c4a106fee07d43332f9.1534336273.git.kshcherbatov@tarantool.org> <20180817101410.zomayvmosk5cp33j@esperanza> <7f51f275-0c09-103b-cb8a-207dc3f77420@tarantool.org> <20180817124641.xpd7tfewdeu6ksvx@esperanza> From: Kirill Shcherbatov Message-ID: Date: Fri, 17 Aug 2018 17:46:49 +0300 MIME-Version: 1.0 In-Reply-To: <20180817124641.xpd7tfewdeu6ksvx@esperanza> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit To: tarantool-patches@freelists.org, Vladimir Davydov List-ID: > What's the point of passing str_len when you can compute it right in > this function with strlen? > > Also, please pass key_end instead of key_len to make function calls more > compact. > > Also, if the function returns bool (which is OK), you shouldn't check > its return value against 0. And you'd better call it xlog_meta_key_match > or xlog_meta_key_equal and make it return true on match and false > otherwise. > > Please fix. diff --git a/src/box/xlog.c b/src/box/xlog.c index 5ed11fc..ed6c06a 100644 --- a/src/box/xlog.c +++ b/src/box/xlog.c @@ -183,6 +183,12 @@ parse_vclock(const char *val, const char *val_end, struct vclock *vclock) return 0; } +static inline bool +xlog_meta_key_equal(const char *key, uint32_t key_len, const char *str) +{ + return key_len == strlen(str) && memcmp(key, str, key_len) == 0; +} + /** * Parse xlog meta from buffer, update buffer read * position in case of success @@ -261,8 +267,9 @@ 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) { + uint32_t key_len = key_end - key; + if (xlog_meta_key_equal(key, key_len, INSTANCE_UUID_KEY) || + xlog_meta_key_equal(key, key_len, INSTANCE_UUID_KEY_V12)) { /* * Instance: */ @@ -277,19 +284,19 @@ 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 (xlog_meta_key_equal(key, key_len, VCLOCK_KEY)) { /* * 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 (xlog_meta_key_equal(key, key_len, PREV_VCLOCK_KEY)) { /* * 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 (xlog_meta_key_equal(key, key_len, VERSION_KEY)) { /* Ignore Version: for now */ } else { /*