From nobody Mon Feb 9 19:54:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617311146; cv=none; d=zohomail.com; s=zohoarc; b=oKqvjFQNgsFMDPs9cLSYvSpAz3FrFdQ6fTbr5UWQNR7RtmmgofFq83nDEN3Xqg6s9NKvayhyytdPrMNmqgmPIIbX7FZkk2bXJLwi5Q+eSgIRMrT6DGL4GVcqWSr1NPbhvJ3z2DajuChDFC8r2CeKHwElQXw7U+a1reEvyDBoVXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617311146; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X91HzjMdIQRC4bFzuA9M8SwZIl0hk0KOPCfh8VRtOKw=; b=h6vzqn+21JirTqBk/HuGNh8ULy5WUj6PMeWBasEeFfvyrTFflUHaxdqO/8Ve/8D6qYaU4TFjesepXirWBECFpqYBYTstSmfAd8j8u/dAEVaClIE3DSwl+9cieHQY5TFU89/gd9NtCK/mLpEuY0IhReoXZj3M6qP3eEpNxvT0tKQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617311146778323.34945785401135; Thu, 1 Apr 2021 14:05:46 -0700 (PDT) Received: from localhost ([::1]:41580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lS4Vd-0001Gq-Ne for importer@patchew.org; Thu, 01 Apr 2021 17:05:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lS4S0-0007Ft-TA for qemu-devel@nongnu.org; Thu, 01 Apr 2021 17:02:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lS4Rx-0003Bk-07 for qemu-devel@nongnu.org; Thu, 01 Apr 2021 17:02:00 -0400 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-243-7r8WrhOaPu2TPidUA8-1wA-1; Thu, 01 Apr 2021 17:01:55 -0400 Received: by mail-ot1-f69.google.com with SMTP id x68so3069792ota.2 for ; Thu, 01 Apr 2021 14:01:54 -0700 (PDT) Received: from redhat.redhat.com (ip68-103-222-6.ks.ok.cox.net. [68.103.222.6]) by smtp.gmail.com with ESMTPSA id g2sm1377891otn.32.2021.04.01.14.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 14:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617310916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X91HzjMdIQRC4bFzuA9M8SwZIl0hk0KOPCfh8VRtOKw=; b=T2b1ZrajK7xDEwQflXc+tB7yuiKLe6d7+HQPT76Cr5TfjYMvjjcbmNw0AqNFxyI6GLFcqT 9oWfoDlRm4fkA7lRCjRaKPNEnkZexnnFToxau6rctad+aH6o5veYWUugQWG2Bv104QDcxd T2JoPKEImnYodUW+QIqjSEo7yTa1xhk= X-MC-Unique: 7r8WrhOaPu2TPidUA8-1wA-1 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=X91HzjMdIQRC4bFzuA9M8SwZIl0hk0KOPCfh8VRtOKw=; b=nMRJu9/u/O1TfxpLC8vnoy8uFTcjJYghoKuhuH1JDZnWZvCr2AlMmsB7avvDGgRLQZ n7GZyvctc/7ow6KLZe6dqso/QKERwTe+PbF3BhwoVoKz9XXupcmQ5Jfni40ZD+WNkfiD WdcOp0tgKF5QPgf04/20PCvD5yasQE9QLqKQ0jWddwza+tBYjHArMa9x/q9+mVOigP+X JtZ9LC/eVosfGypt99RfV4jXMFPuT2C+6wcPqTn6cYRcZogsChm3vbpmzrWQmBIFySED lS0tPkFllgBwrN4rTu9TNWY8NshP3wbt3uwoiR+5Jf7RCgD+eb0hd8bnEmwHbvlKfOnG SAiA== X-Gm-Message-State: AOAM533xWly0xal35w2Vq88yE5gTRXlfgDo/kd7TcbV2R0Kf4BsqWAEw ZJdN21yqbPHgh/2fWYiQuyWhMO2QzD/q+gMWWCrvkeqjWZFnkuBWTr6I7p8JFd1JJhXgRW7TqyK 852yMLLgipprpfpY= X-Received: by 2002:a9d:4d8f:: with SMTP id u15mr8585324otk.296.1617310914230; Thu, 01 Apr 2021 14:01:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOK+BZS1JYunOZ/K04nXecEAA50gg39Nh0Z81yTmYThiAuDyJ+zIJsck3paEYw8O4lLDD6jA== X-Received: by 2002:a9d:4d8f:: with SMTP id u15mr8585308otk.296.1617310914017; Thu, 01 Apr 2021 14:01:54 -0700 (PDT) From: Connor Kuehl To: qemu-block@nongnu.org Subject: [PATCH v2 2/2] block/rbd: Add an escape-aware strchr helper Date: Thu, 1 Apr 2021 16:01:50 -0500 Message-Id: <20210401210150.2127670-3-ckuehl@redhat.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210401210150.2127670-1-ckuehl@redhat.com> References: <20210401210150.2127670-1-ckuehl@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ckuehl@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=ckuehl@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, dillaman@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Sometimes the parser needs to further split a token it has collected from the token input stream. Right now, it does a cursory check to see if the relevant characters appear in the token to determine if it should break it down further. However, qemu_rbd_next_tok() will escape characters as it removes tokens from the token stream and plain strchr() won't. This can make the initial strchr() check slightly misleading since it implies qemu_rbd_next_tok() will find the token and split on it, except the reality is that qemu_rbd_next_tok() will pass over it if it is escaped. Use a custom strchr to avoid mixing escaped and unescaped string operations. Reported-by: Han Han Fixes: https://bugzilla.redhat.com/1873913 Signed-off-by: Connor Kuehl --- block/rbd.c | 20 ++++++++++++++++++-- tests/qemu-iotests/231 | 4 ++++ tests/qemu-iotests/231.out | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 9071a00e3f..c0e4d4a952 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -134,6 +134,22 @@ static char *qemu_rbd_next_tok(char *src, char delim, = char **p) return src; } =20 +static char *qemu_rbd_strchr(char *src, char delim) +{ + char *p; + + for (p =3D src; *p; ++p) { + if (*p =3D=3D delim) { + return p; + } + if (*p =3D=3D '\\') { + ++p; + } + } + + return NULL; +} + static void qemu_rbd_unescape(char *src) { char *p; @@ -171,7 +187,7 @@ static void qemu_rbd_parse_filename(const char *filenam= e, QDict *options, qemu_rbd_unescape(found_str); qdict_put_str(options, "pool", found_str); =20 - if (strchr(p, '@')) { + if (qemu_rbd_strchr(p, '@')) { image_name =3D qemu_rbd_next_tok(p, '@', &p); =20 found_str =3D qemu_rbd_next_tok(p, ':', &p); @@ -181,7 +197,7 @@ static void qemu_rbd_parse_filename(const char *filenam= e, QDict *options, image_name =3D qemu_rbd_next_tok(p, ':', &p); } /* Check for namespace in the image_name */ - if (strchr(image_name, '/')) { + if (qemu_rbd_strchr(image_name, '/')) { found_str =3D qemu_rbd_next_tok(image_name, '/', &image_name); qemu_rbd_unescape(found_str); qdict_put_str(options, "namespace", found_str); diff --git a/tests/qemu-iotests/231 b/tests/qemu-iotests/231 index 0f66d0ca36..8e6c6447c1 100755 --- a/tests/qemu-iotests/231 +++ b/tests/qemu-iotests/231 @@ -55,6 +55,10 @@ _filter_conf() $QEMU_IMG info "json:{'file.driver':'rbd','file.filename':'rbd:rbd/bogus:c= onf=3D${BOGUS_CONF}'}" 2>&1 | _filter_conf $QEMU_IMG info "json:{'file.driver':'rbd','file.pool':'rbd','file.image':'= bogus','file.conf':'${BOGUS_CONF}'}" 2>&1 | _filter_conf =20 +# Regression test: the qemu-img invocation is expected to fail, but it sho= uld +# not seg fault the parser. +$QEMU_IMG create "rbd:rbd/aa\/bb:conf=3D${BOGUS_CONF}" 1M 2>&1 | _filter_c= onf + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/231.out b/tests/qemu-iotests/231.out index 747dd221bb..a785a6e859 100644 --- a/tests/qemu-iotests/231.out +++ b/tests/qemu-iotests/231.out @@ -4,4 +4,7 @@ unable to get monitor info from DNS SRV with service name: = ceph-mon qemu-img: Could not open 'json:{'file.driver':'rbd','file.filename':'rbd:r= bd/bogus:conf=3DBOGUS_CONF'}': error connecting: No such file or directory unable to get monitor info from DNS SRV with service name: ceph-mon qemu-img: Could not open 'json:{'file.driver':'rbd','file.pool':'rbd','fil= e.image':'bogus','file.conf':'BOGUS_CONF'}': error connecting: No such file= or directory +Formatting 'rbd:rbd/aa\/bb:conf=3DBOGUS_CONF', fmt=3Draw size=3D1048576 +unable to get monitor info from DNS SRV with service name: ceph-mon +qemu-img: rbd:rbd/aa\/bb:conf=3DBOGUS_CONF: error connecting: No such file= or directory *** done --=20 2.30.2