From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 381772999B for ; Thu, 11 Apr 2019 18:22:33 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 48GSraD0QRrw for ; Thu, 11 Apr 2019 18:22:33 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E42C329903 for ; Thu, 11 Apr 2019 18:22:32 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 1/6] swim: factor out MP_BIN decoding from swim_decode_uuid Date: Fri, 12 Apr 2019 01:22:25 +0300 Message-Id: <74e22eed2a53e8aa89a0bafafd5d70d2c19aa49e.1555021137.git.v.shpilevoy@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org The new function is swim_decode_bin(), and is going to be used to safely decode payloads - arbitrary binary data disseminated alongside with all the other SWIM member attributes. Part of #3234 --- src/lib/swim/swim_proto.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/lib/swim/swim_proto.c b/src/lib/swim/swim_proto.c index fa02b61c4..700eff431 100644 --- a/src/lib/swim/swim_proto.c +++ b/src/lib/swim/swim_proto.c @@ -120,9 +120,9 @@ swim_decode_port(struct sockaddr_in *address, const char **pos, const char *end, return 0; } -int -swim_decode_uuid(struct tt_uuid *uuid, const char **pos, const char *end, - const char *prefix, const char *param_name) +static inline int +swim_decode_bin(const char **bin, uint32_t *size, const char **pos, + const char *end, const char *prefix, const char *param_name) { if (mp_typeof(**pos) != MP_BIN || *pos == end || mp_check_binl(*pos, end) > 0) { @@ -130,12 +130,27 @@ swim_decode_uuid(struct tt_uuid *uuid, const char **pos, const char *end, param_name); return -1; } - if (mp_decode_binl(pos) != UUID_LEN || *pos + UUID_LEN > end) { + *bin = mp_decode_bin(pos, size); + if (*pos > end) { + diag_set(SwimError, "%s %s is invalid", prefix, param_name); + return -1; + } + return 0; +} + +int +swim_decode_uuid(struct tt_uuid *uuid, const char **pos, const char *end, + const char *prefix, const char *param_name) +{ + uint32_t size; + const char *bin; + if (swim_decode_bin(&bin, &size, pos, end, prefix, param_name) != 0) + return -1; + if (size != UUID_LEN) { diag_set(SwimError, "%s %s is invalid", prefix, param_name); return -1; } - memcpy(uuid, *pos, UUID_LEN); - *pos += UUID_LEN; + memcpy(uuid, bin, UUID_LEN); return 0; } -- 2.17.2 (Apple Git-113)