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 5F3D12C7A3 for ; Wed, 15 May 2019 15:36:50 -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 bIRPSzv9GftM for ; Wed, 15 May 2019 15:36:50 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 15F702EC2F for ; Wed, 15 May 2019 15:36:50 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 03/10] swim: validate URI in swim_probe_member() Date: Wed, 15 May 2019 22:36:40 +0300 Message-Id: <471b5dd2140756e7f9928e3ba6be48a898ad788f.1557948687.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Similar methods validate their arguments: add_member, remove_member. Validate here as well for consistency. Part of #3234 --- src/lib/swim/swim.c | 4 ++++ test/unit/swim.c | 3 ++- test/unit/swim.result | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index a9a0a39b3..fb2b1490b 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -1890,6 +1890,10 @@ int swim_probe_member(struct swim *swim, const char *uri) { assert(swim_is_configured(swim)); + if (uri == NULL) { + diag_set(SwimError, "swim.probe_member: URI is mandatory"); + return -1; + } struct sockaddr_in addr; if (swim_uri_to_addr(uri, &addr, "swim.probe_member:") != 0) return -1; diff --git a/test/unit/swim.c b/test/unit/swim.c index d9613e8e0..c6ef1eebc 100644 --- a/test/unit/swim.c +++ b/test/unit/swim.c @@ -359,12 +359,13 @@ swim_test_basic_gossip(void) static void swim_test_probe(void) { - swim_start_test(2); + swim_start_test(3); struct swim_cluster *cluster = swim_cluster_new(2); struct swim *s1 = swim_cluster_member(cluster, 0); struct swim *s2 = swim_cluster_member(cluster, 1); const char *s2_uri = swim_member_uri(swim_self(s2)); + is(swim_probe_member(s1, NULL), -1, "probe validates URI"); is(swim_probe_member(s1, s2_uri), 0, "send probe"); is(swim_cluster_wait_fullmesh(cluster, 0.1), 0, "receive ACK on probe and get fullmesh") diff --git a/test/unit/swim.result b/test/unit/swim.result index 266d83589..587f66c7a 100644 --- a/test/unit/swim.result +++ b/test/unit/swim.result @@ -78,9 +78,10 @@ ok 5 - subtests ok 6 - subtests *** swim_test_basic_failure_detection: done *** *** swim_test_probe *** - 1..2 - ok 1 - send probe - ok 2 - receive ACK on probe and get fullmesh + 1..3 + ok 1 - probe validates URI + ok 2 - send probe + ok 3 - receive ACK on probe and get fullmesh ok 7 - subtests *** swim_test_probe: done *** *** swim_test_refute *** -- 2.20.1 (Apple Git-117)