From nobody Mon Feb 9 00:07:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571925487; cv=none; d=zoho.com; s=zohoarc; b=LPItkpI6KPa7P3FFdMqKUYUYCb0mWOJtvJdRJG2ERxnF0CoVKdAr1I5tgQ95wjx+3W2puTxWWzKfo8V14JMkoKELzSpF7BrCD2mMrdwQ5rsC/zS7/X7F0HGwYEbFuEsUr/Xb9/vhPHpuYr9OtaEdpK3/1aEGBINMXZ7Us/AwzU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925487; h=Content-Type:Content-Transfer-Encoding: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=1PceDF0Cuomw0E1dUVWGuV+fdfXscj2pM6I5rvdDdq4=; b=atvKN7cr2ilJvx/PtBamL3HkdLVORTyOFDuq+EW1rTrRAzfOdrKbYC5CIjyxuXmr+4zrBrTZqqCg5AlVZKR/1/ixs20EcvDQyKPLnWAba8F/gL8743i/17+LxTr1ycx0ZODVGKxpiU/YocqXeg1TzMrQctTEnJADlcgbXTveda4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (207.211.31.81 [207.211.31.81]) by mx.zohomail.com with SMTPS id 15719254874671002.628336586974; Thu, 24 Oct 2019 06:58:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-jyHu2_5FORCFulsJbKG2qw-1; Thu, 24 Oct 2019 09:57:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 06C255E4; Thu, 24 Oct 2019 13:57:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2DDF5C219; Thu, 24 Oct 2019 13:57:10 +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 9334B180BA9E; Thu, 24 Oct 2019 13:57:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv6xB026412 for ; Thu, 24 Oct 2019 09:57:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2216D10098FB; Thu, 24 Oct 2019 13:57:06 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FABC10027AB for ; Thu, 24 Oct 2019 13:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925486; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1PceDF0Cuomw0E1dUVWGuV+fdfXscj2pM6I5rvdDdq4=; b=G1MAiuRxMAAvQbVO0zVmLDxcei2sMNCqadMo3xCjMzIXitOuddjb5Ql73As9R9dBzMQIXK ZxUmw9VIqoIaKmfX1Qph/WmtRiDRDsKMMz1uHPxJy0feQOo7fUafyYhqBjz9lXfUUiihZ2 OOwRBPlDkPYT+cXcY0kfQ04CiVse/dY= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:31 +0200 Message-Id: <3826fc4af4ce8dd2164bbc70c176e1b18b578869.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/19] util: buffer: Properly URLencode strings X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: jyHu2_5FORCFulsJbKG2qw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" According to rfc3986: 2.3. Unreserved Characters Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde. unreserved =3D ALPHA / DIGIT / "-" / "." / "_" / "~" URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers. Thus we must not include few other characters which don't match c_isalpha to conform to the rules. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 14 ++++++++++++-- tests/viruritest.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bf703fe7a5..bde118a248 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -638,6 +638,16 @@ virBufferEscape(virBufferPtr buf, char escape, const c= har *toescape, } +static bool +virBufferURIEncodeCharIsUnencoded(char c) +{ + if (c =3D=3D '-' || c =3D=3D '.' || c =3D=3D '_' || c =3D=3D '~') + return true; + + return c_isalnum(c); +} + + /** * virBufferURIEncodeString: * @buf: the buffer to append to @@ -664,7 +674,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) virBufferAddLit(buf, ""); /* auto-indent */ for (p =3D str; *p; ++p) { - if (c_isalnum(*p)) + if (virBufferURIEncodeCharIsUnencoded(*p)) grow_size++; else grow_size +=3D 3; /* %ab */ @@ -674,7 +684,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) return; for (p =3D str; *p; ++p) { - if (c_isalnum(*p)) { + if (virBufferURIEncodeCharIsUnencoded(*p)) { buf->content[buf->use++] =3D *p; } else { uc =3D (unsigned char) *p; diff --git a/tests/viruritest.c b/tests/viruritest.c index 3255e2333a..a11587e52b 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -184,7 +184,7 @@ mymain(void) { NULL, NULL, false }, }; TEST_FULL("spice://[3ffe::104]:5900/?tlsSubject=3DC=3DXX,L=3DTesttown,= O=3DTest%20Company,CN=3Dtester.test", - "spice://[3ffe::104]:5900/?tlsSubject=3DC%3dXX%2cL%3dTesttow= n%2cO%3dTest%20Company%2cCN%3dtester%2etest", + "spice://[3ffe::104]:5900/?tlsSubject=3DC%3dXX%2cL%3dTesttow= n%2cO%3dTest%20Company%2cCN%3dtester.test", "spice", "3ffe::104", 5900, "/", "tlsSubject=3DC=3DXX,L=3DTe= sttown,O=3DTest%20Company,CN=3Dtester.test", NULL, NULL, spiceparams); virURIParam params1[] =3D { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list