From patchwork Mon May 15 15:37:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 9727375 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C35C6028A for ; Mon, 15 May 2017 15:39:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06CAC28990 for ; Mon, 15 May 2017 15:39:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFCE628995; Mon, 15 May 2017 15:39:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A3CC028990 for ; Mon, 15 May 2017 15:39:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90CA7BDD4; Mon, 15 May 2017 15:39:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 90CA7BDD4 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 90CA7BDD4 Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 748645DD6E; Mon, 15 May 2017 15:39:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4122C4A48D; Mon, 15 May 2017 15:39:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FFcTOJ008021 for ; Mon, 15 May 2017 11:38:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FE254DA31; Mon, 15 May 2017 15:38:29 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFF2E5C88C; Mon, 15 May 2017 15:38:26 +0000 (UTC) Received: from prv3-mh.provo.novell.com (prv3-mh.provo.novell.com [137.65.250.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27D615F754; Mon, 15 May 2017 15:38:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27D615F754 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mwilck@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 27D615F754 Received: from apollon.suse.de.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Mon, 15 May 2017 09:38:05 -0600 From: Martin Wilck To: Christophe Varoqui , Hannes Reinecke , Benjamin Marzinski Date: Mon, 15 May 2017 17:37:14 +0200 Message-Id: <20170515153722.11508-5-mwilck@suse.com> In-Reply-To: <20170515153722.11508-1-mwilck@suse.com> References: <20170515153722.11508-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 15 May 2017 15:38:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 15 May 2017 15:38:19 +0000 (UTC) for IP:'137.65.250.26' DOMAIN:'prv3-mh.provo.novell.com' HELO:'prv3-mh.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.501 (BAYES_50, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.26 prv3-mh.provo.novell.com 137.65.250.26 prv3-mh.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH v2 04/12] kpartx: relax and improve UUID check in dm_compare_uuid X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 15 May 2017 15:39:34 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP It is wrong to assume that UUIDs of parent devices always contain "mpath". Fix that, and make the check for the kpartx-specific prefix "part%d-" stricter and more explicit. Moreover, avoid duplication of string constants and properly express the dependencies of the various constants. Signed-off-by: Martin Wilck --- kpartx/devmapper.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index 8aca9592..8b125be5 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -10,8 +10,10 @@ #include #include "devmapper.h" -#define UUID_PREFIX "part%d-" -#define MAX_PREFIX_LEN 8 +#define _UUID_PREFIX "part" +#define UUID_PREFIX _UUID_PREFIX "%d-" +#define _UUID_PREFIX_LEN (sizeof(_UUID_PREFIX) - 1) +#define MAX_PREFIX_LEN (_UUID_PREFIX_LEN + 4) #define PARAMS_SIZE 1024 int dm_prereq(char * str, int x, int y, int z) @@ -417,9 +419,13 @@ dm_compare_uuid(const char *mapuuid, const char *partname) if (!partuuid) return 1; - if (!strncmp(partuuid, "part", 4)) { - char *p = strstr(partuuid, "mpath-"); - if (p && !strcmp(mapuuid, p)) + if (!strncmp(partuuid, _UUID_PREFIX, _UUID_PREFIX_LEN)) { + char *p = partuuid + _UUID_PREFIX_LEN; + /* skip partition number */ + while (isdigit(*p)) + p++; + if (p != partuuid + _UUID_PREFIX_LEN && *p == '-' && + !strcmp(mapuuid, p + 1)) r = 0; } free(partuuid);