From patchwork Sun Apr 30 23:22:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 756945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wGNsw4K98z9s9c for ; Mon, 1 May 2017 09:24:04 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C95EAB1E; Sun, 30 Apr 2017 23:22:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 87D3AB0B for ; Sun, 30 Apr 2017 23:22:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5AD11193 for ; Sun, 30 Apr 2017 23:22:47 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id 3B0E3402F2; Mon, 1 May 2017 01:22:46 +0200 (CEST) Received: from mfilter18-d.gandi.net (mfilter18-d.gandi.net [217.70.178.146]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 2A69D41C07E; Mon, 1 May 2017 01:22:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter18-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter18-d.gandi.net (mfilter18-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id BF7iwk91j48y; Mon, 1 May 2017 01:22:44 +0200 (CEST) X-Originating-IP: 173.228.112.23 Received: from sigabrt.gateway.sonic.net (173-228-112-23.dsl.dynamic.fusionbroadband.com [173.228.112.23]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 7643C41C07D; Mon, 1 May 2017 01:22:43 +0200 (CEST) From: Ben Pfaff To: dev@openvswitch.org Date: Sun, 30 Apr 2017 16:22:06 -0700 Message-Id: <20170430232231.15151-3-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170430232231.15151-1-blp@ovn.org> References: <20170430232231.15151-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 02/27] uuid: Change semantics of uuid_is_partial_string(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Until now, uuid_is_partial_string() returned the number of characters at the beginning of a string that were the beginning of a valid UUID. This is useful, but all of the callers actually wanted to get a value of 0 if the string contained a character that was invalid for a UUID. This makes that change. Examples: "123" previously yielded 3 and still does. "xyzzy" previously yielded 0 and still does. "123xyzzy" previously yielded 3, now yields 0. "e66250bb-9531-491b-b9c3-5385cabb0080" previously yielded 36, still does. "e66250bb-9531-491b-b9c3-5385cabb0080xyzzy" previously yielded 36, now 0. Signed-off-by: Ben Pfaff Acked-by: Russell Bryant --- lib/db-ctl-base.c | 4 +--- lib/uuid.c | 30 +++++++++++++++++++++--------- ovn/utilities/ovn-sbctl.c | 4 ++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index ad98454c903d..ab617f9e065d 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -338,9 +338,7 @@ get_row(struct ctl_context *ctx, } } } - if (!row - && record_id[uuid_is_partial_string(record_id)] == '\0' - && strlen(record_id) >= 4) { + if (!row && uuid_is_partial_string(record_id) >= 4) { for (const struct ovsdb_idl_row *r = ovsdb_idl_first_row(ctx->idl, table); r != NULL; diff --git a/lib/uuid.c b/lib/uuid.c index a9094d36789a..636492bcbe5b 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009, 2010, 2011, 2013, 2016 Nicira, Inc. +/* Copyright (c) 2008, 2009, 2010, 2011, 2013, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -211,22 +211,34 @@ error: return false; } -/* Returns the number of characters at the beginning of 's' that are valid for - * a UUID. For example, the "123" at the beginning of "123xyzzy" could begin a - * UUID, so uuid_is_partial_string() would return 3; for "xyzzy", this function - * would return 0, since "x" can't start a UUID. */ +/* If 's' is a string representation of a UUID, or the beginning of one, + * returns strlen(s), otherwise 0. + * + * For example: + * + * "123" yields 3 + * "xyzzy" yields 0 + * "123xyzzy" yields 0 + * "e66250bb-9531-491b-b9c3-5385cabb0080" yields 36 + * "e66250bb-9531-491b-b9c3-5385cabb0080xyzzy" yields 0 + */ int uuid_is_partial_string(const char *s) { static const char tmpl[UUID_LEN] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; size_t i; for (i = 0; i < UUID_LEN; i++) { - if (tmpl[i] == 'x' - ? hexit_value(s[i]) < 0 - : s[i] != '-') { - break; + if (s[i] == '\0') { + return i; + } else if (tmpl[i] == 'x' + ? hexit_value(s[i]) < 0 + : s[i] != '-') { + return 0; } } + if (s[i] != '\0') { + return 0; + } return i; } diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index ac292f316086..ac37d6014838 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -700,14 +700,14 @@ static char * parse_partial_uuid(char *s) { /* Accept a full or partial UUID. */ - if (uuid_is_partial_string(s) == strlen(s)) { + if (uuid_is_partial_string(s)) { return 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) == strlen(s + 2)) { + && uuid_is_partial_string(s + 2)) { return s + 2; }