From patchwork Tue Apr 20 22:22:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Roytman X-Patchwork-Id: 1468508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fj6P6WeB; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FPyrG3ZWzz9vFF for ; Wed, 21 Apr 2021 08:23:26 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id BB444404BA; Tue, 20 Apr 2021 22:23:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zOkrPg7CXVLg; Tue, 20 Apr 2021 22:23:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id 0ABD140264; Tue, 20 Apr 2021 22:23:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D3749C000F; Tue, 20 Apr 2021 22:23:22 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C565C000B for ; Tue, 20 Apr 2021 22:23:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 05F844033B for ; Tue, 20 Apr 2021 22:23:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FqJLRIj2VGQc for ; Tue, 20 Apr 2021 22:23:16 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by smtp2.osuosl.org (Postfix) with ESMTPS id 472DC40264 for ; Tue, 20 Apr 2021 22:23:16 +0000 (UTC) Received: by mail-ed1-x533.google.com with SMTP id cq11so3350668edb.0 for ; Tue, 20 Apr 2021 15:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ruPozM/LqSWcjjKEg3C4Q8JSVCZfoc75Hj9hm+4KhLY=; b=fj6P6WeBZLHoDwIn5AkJqFvC4fUsyK+yv4ba78Ylpg1LQ3TW/V3rxRG8BSR9JSUw7v FoWbVDbe0fHxzjMpPG3Jp8ppOQczc8Lj1GoSxk6X+8m75+c0byDjl5B24Q4gFsK8lqHn KcldKHWHZTLh1DDHXcvx7t/D0oJghA6zfOUtMbGCK/158awKvZ0nR5L5MCBUJi80vMKs sdsUFYvmjKTpPrmhWZGSAm7zo3sNGxuD9/sqzoeC7LMPG4RaruyjDEhN/UH/rkb0Tlbh kSBj0OZOTGmF4XdbjqZ2JQiV4w34mSIxK1h6pmt3xCAbnmF8em1hz8a5Ce5VvpxTmtLx IWJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ruPozM/LqSWcjjKEg3C4Q8JSVCZfoc75Hj9hm+4KhLY=; b=VuETgJlBqrn9eHMi+Kyo+TkmlHgfhrA9CJv5n89Aes2azDLH4ubXZo0a2lOxCX7a5W lRYfQu3Srm+eoQcnXf+q2FeVRh+PgISRWgvCMi6qM6yuZ5aX86CH1OGFANw84h2sv7S5 qvK1jldQGntbAfn26jD/UWBQQ4iJsvDqymYF5mntbfASDhZ8x5O6XefWVjZt5KsNTap6 W5ycfa315wawDp6lEoYub4+MLhu933kMMecC5ee1/u6MktvZHfigeY7rjOWdXDhL/R2W d3DGAvbLbLPUv9n3Fck0BuB/ctvBbkjDBAC/HgkbimKn+bn5Np9vYA6RqwnZEXXEbB/8 5K7A== X-Gm-Message-State: AOAM533FpHpr39a2dqPetepLS4gH7VYcN9bAKPBIO+VLQRAJQiT/R3hl 53nZFJqzZAc8C+q32lydTDKaN56eY3sd7g== X-Google-Smtp-Source: ABdhPJwjxZlCyiWga95f21v/sc0eZexgndjFvzzk3w4HZJY9NvTblkx8FJCL+tvUvj1Tfn8u2x5otQ== X-Received: by 2002:a50:fe81:: with SMTP id d1mr35729297edt.308.1618957394326; Tue, 20 Apr 2021 15:23:14 -0700 (PDT) Received: from localhost (93-173-39-210.bb.netvision.net.il. [93.173.39.210]) by smtp.gmail.com with ESMTPSA id k12sm482632edo.50.2021.04.20.15.23.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Apr 2021 15:23:13 -0700 (PDT) From: Alexey Roytman To: ovs-dev@openvswitch.org Date: Wed, 21 Apr 2021 01:22:55 +0300 Message-Id: <20210420222255.45203-1-aroytman@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Cc: Alexey Roytman Subject: [ovs-dev] [PATCH v2 ovn] ovn-sbctl: Prevent core dump from ovn-sbctl lflow-list [datpath] 0xflow X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Alexey Roytman When ovn-sbctl lflow-list gets lflow argument with 0x prefix, e.g. 0x8131c8a8, it prints correct output, but fails with coredump. For example: ovn-sbctl --uuid lflow-list sw1 0x8131c8a8 Datapath: "sw1" (4b1e53d8-9f0f-4768-b4a6-6cbc58a4bfda) Pipeline: egress uuid=0x8131c8a8, table=10(ls_out_port_sec_l2 ), priority=100 , match=(eth.mcast), action=(output;) free(): invalid pointer [2] 616553 abort (core dumped) ovn-sbctl --uuid dump-flows sw1 0x8131c8a8 This patch fixes it. Signed-off-by: Alexey Roytman --- utilities/ovn-sbctl.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c index e3aa7a68e..099d31f08 100644 --- a/utilities/ovn-sbctl.c +++ b/utilities/ovn-sbctl.c @@ -764,6 +764,12 @@ sbctl_lflow_cmp(const void *a_, const void *b_) return cmp ? cmp : strcmp(a->actions, b->actions); } +static bool +is_uuid_with_prefix(const char *uuid) +{ + return uuid[0] == '0' && (uuid[1] == 'x' || uuid[1] == 'X'); +} + static char * parse_partial_uuid(char *s) { @@ -774,8 +780,7 @@ parse_partial_uuid(char *s) /* Accept a full or partial UUID prefixed by 0x, since "ovs-ofctl * dump-flows" prints cookies prefixed by 0x. */ - if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X') - && uuid_is_partial_string(s + 2)) { + if (is_uuid_with_prefix(s) && uuid_is_partial_string(s + 2)) { return s + 2; } @@ -799,8 +804,11 @@ is_partial_uuid_match(const struct uuid *uuid, const char *match) * from UUIDs, and cookie values are printed without leading zeros because * they're just numbers. */ const char *s1 = strip_leading_zero(uuid_s); - const char *s2 = strip_leading_zero(match); - + const char *s2 = match; + if (is_uuid_with_prefix(s2)) { + s2 = s2 + 2; + } + s2 = strip_leading_zero(s2); return !strncmp(s1, s2, strlen(s2)); } @@ -1139,7 +1147,6 @@ cmd_lflow_list(struct ctl_context *ctx) ctl_fatal("%s is not a UUID or the beginning of a UUID", ctx->argv[i]); } - ctx->argv[i] = s; } struct vconn *vconn = sbctl_open_vconn(&ctx->options);