string->uri-reference rejects domain names with final ‘.’

  • Done
  • quality assurance status badge
Details
3 participants
  • Dr. Arne Babenhauserheide
  • dsmich
  • Tobias Geerinckx-Rice
Owner
unassigned
Submitted by
Tobias Geerinckx-Rice
Severity
normal

Debbugs page

Tobias Geerinckx-Rice wrote 3 years ago
(address . bug-guile@gnu.org)
877db5ldok.fsf@nckx
Guilers,

What the subject says :-) Omitting the final dot is optional (and
common), not mandatory.

scheme@(guile-user)> (string->uri-reference "http://x.org")
$1 = #<<uri> … host: "x.org" …>

scheme@(guile-user)> (string->uri-reference "http://x.org.")
$2 = #f ; wrong!

This actually breaks redirects in the wild:

Starting download […]
From
Bad uri-reference header component:
https://pyropus.ca./software/getmail/old-versions/getmail-5.16.tar.gz

Kind regards,

T G-R
-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYd5oew0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW15fc4A/3vxSxEPLggOtdLGfj3lNJCfouOy3YO5jy2PYugP
evlWAQD+JTQCfsOlPIn8uD/rv/KQZ1Gb5r0g/SWax/dhdmRdAg==
=gyJt
-----END PGP SIGNATURE-----

dsmich wrote 3 years ago
(name . 'Tobias Geerinckx-Rice')(address . me@tobias.gr)(name . '53201@debbugs.gnu.org')(address . 53201@debbugs.gnu.org)
cad498fa10c07336957258006a96632d9c90e510@webmail
Probably not the best fix. Seems to work. Includes a few tests.

-Dale

Toggle diff (41 lines)
diff --git a/module/web/uri.scm b/module/web/uri.scm
index 8e0b9bee7..d6758fcc6 100644
--- a/module/web/uri.scm
+++ b/module/web/uri.scm
@@ -212,7 +212,9 @@ for ‘build-uri’ except there is no scheme."
(and (regexp-exec domain-label-regexp
(substring host start end))
(lp (1+ end)))
- (regexp-exec top-label-regexp host start)))))))
+ (if (< start (string-length host))
+ (regexp-exec top-label-regexp host start)
+ #t)))))))

(define userinfo-pat
(string-append "[" letters digits "_.!~*'();:&=+$,-]+"))
diff --git a/test-suite/tests/web-uri.test
b/test-suite/tests/web-uri.test
index 95fd82f16..c49142d48 100644
--- a/test-suite/tests/web-uri.test
+++ b/test-suite/tests/web-uri.test
@@ -367,6 +367,9 @@
(pass-if "//bad.host.1"
(not (string->uri-reference "//bad.host.1")))

+ (pass-if "//bad.host.."
+ (not (string->uri-reference "//bad.host..")))
+
(pass-if "http://1.good.host"
(uri=? (string->uri-reference "http://1.good.host")
#:scheme 'http #:host "1.good.host" #:path ""))
@@ -375,6 +378,10 @@
(uri=? (string->uri-reference "//1.good.host")
#:host "1.good.host" #:path ""))

+ (pass-if "//1.good.host."
+ (uri=? (string->uri-reference "//1.good.host.")
+ #:host "1.good.host." #:path ""))
+
(when (memq 'socket *features*)
(pass-if "http://192.0.2.1"
(uri=? (string->uri-reference "http://192.0.2.1")
Attachment: file
dsmich wrote 3 years ago
(name . 'Tobias Geerinckx-Rice')(address . me@tobias.gr)(name . '53201@debbugs.gnu.org')(address . 53201@debbugs.gnu.org)
2e32758c10ad8be43ebe3b7ec96884b8b0d85d97@webmail
New patch. Now with 3 test cases!

-Dale
Attachment: file
From f4eece6395e75197030bff42a583e847e5a34e15 Mon Sep 17 00:00:00 2001
From: "Dale P. Smith" <dalepsmith@gmail.com>
Date: Thu, 27 Jan 2022 19:20:57 -0500
Subject: [PATCH] Allow trailing "." in urls

bug #53201
---
module/web/uri.scm | 17 ++++++++++-------
test-suite/tests/web-uri.test | 10 ++++++++++
2 files changed, 20 insertions(+), 7 deletions(-)

Toggle diff (51 lines)
diff --git a/module/web/uri.scm b/module/web/uri.scm
index 8e0b9bee7..8c5c0d6f0 100644
--- a/module/web/uri.scm
+++ b/module/web/uri.scm
@@ -206,13 +206,16 @@ for ‘build-uri’ except there is no scheme."
((regexp-exec ipv6-regexp host)
(false-if-exception (inet-pton AF_INET6 host)))
(else
- (let lp ((start 0))
- (let ((end (string-index host #\. start)))
- (if end
- (and (regexp-exec domain-label-regexp
- (substring host start end))
- (lp (1+ end)))
- (regexp-exec top-label-regexp host start)))))))
+ (let ((last (1- (string-length host))))
+ (let lp ((start 0))
+ (let ((end (string-index host #\. start)))
+ (if (and end (< end last))
+ (and (regexp-exec domain-label-regexp
+ (substring host start end))
+ (lp (1+ end)))
+ (if end
+ (regexp-exec top-label-regexp (substring host start end))
+ (regexp-exec top-label-regexp host start)))))))))
(define userinfo-pat
(string-append "[" letters digits "_.!~*'();:&=+$,-]+"))
diff --git a/test-suite/tests/web-uri.test b/test-suite/tests/web-uri.test
index 95fd82f16..e9fb766f0 100644
--- a/test-suite/tests/web-uri.test
+++ b/test-suite/tests/web-uri.test
@@ -367,6 +367,16 @@
(pass-if "//bad.host.1"
(not (string->uri-reference "//bad.host.1")))
+ (pass-if "//bad.host.1."
+ (not (string->uri-reference "//bad.host.1.")))
+
+ (pass-if "//bad.host.."
+ (not (string->uri-reference "//bad.host..")))
+
+ (pass-if "//1.good.host."
+ (uri=? (string->uri-reference "//1.good.host.")
+ #:host "1.good.host." #:path ""))
+
(pass-if "http://1.good.host"
(uri=? (string->uri-reference "http://1.good.host")
#:scheme 'http #:host "1.good.host" #:path ""))
--
2.30.2
Dr. Arne Babenhauserheide wrote 2 weeks ago
control message for bug #53201
(address . control@debbugs.gnu.org)
875xkr6mwn.fsf@web.de
close 53201
quit
Dr. Arne Babenhauserheide wrote 2 weeks ago
Re: bug#53201: string->uri-reference rejects domain names with final ‘.’
(address . dsmich@roadrunner.com)(name . '53201@debbugs.gnu.org')(address . 53201@debbugs.gnu.org)(name . 'Tobias Geerinckx-Rice')(address . me@tobias.gr)
87y0xn587i.fsf@web.de
Merged — thank you for the report and the fix!

- Arne
-----BEGIN PGP SIGNATURE-----

iQJEBAEBCAAuFiEE801qEjXQSQPNItXAE++NRSQDw+sFAmfE6DIQHGFybmVfYmFi
QHdlYi5kZQAKCRAT741FJAPD6444EADDcg3qUSUMWuXfD27MjObnS6NrTbZyE9pv
Hc06XdoYa31GmczXT4b/T4G6hJ7iDOCp3qDmcpY8ioZKYJ5o4JJ56pk+1LTpIk27
3FRm2k4UFsWibEMUwte7BR6GAdg06tpoY6vHXaisBi8tZeGO/8AI+6inctCdJ04L
HopfRPG97oMMyUScghLiZPIfantUeH0BOQLovPj4szvJi9tVvXUZZ52Jv8dCGEvE
SfmgEznqKoI+swXthIcKjapjXWkGpK/nu6eUChBVCyPGExoyPBrrjIiWUdwFT8e2
cAd1Mvez3m6T63D3fJkNOHV4jnqAZGkNClWT4aApFoKYWUXbkO8C8hsdD0jDC0iS
gxmjNjowmZao5xPWp1sl1a3NVT/XPkxxQwujjmBUykLoAup3oVijNTyrJhrp/w9S
XTMvGy8cEPk60cIb4Nfig+UteOkrSfO9oYDJwdaqUlyfe5DtSiDHA3yKBtQ1y9KL
OK0UuyXYQr0S4kHF+/xqMQ1b2+tOuTais+xOD55Ygv0gaEL0TRtDyfYgiLoPZ3LV
1sSklnKjc1idgZY0HilSvMLh5wVGDCLFr5Sc6FtQocETX7s5dkkp3wIdY3T2tp3f
hpjJh6mSfK0pC2qcAkUETBJB6TINA6myM+8hsaCT8ogqu91ZpSam9j2PGJ1+Qpky
Gt9Q7O6GcYjEBAEBCAAuFiEE3Si95tmHXKvOSosd3M8NswvBBUgFAmfE6DIQHGFy
bmVfYmFiQHdlYi5kZQAKCRDczw2zC8EFSHxiBACZ+nYye0HJsvBJSverM8yur+96
5l3neol9u63Gg0jEXOk5jSYHTf71/GCZrWe2a5TdFDqEtoPERfYDtBADpLyww4Tf
MZ62vb2wkqAh6jtLEG9M1Jld0QfifEON4kDC+Zj6GJPaakPY+fpZDiqWaBx1LUbM
nozfXe/fxu+4nMPuBw==
=uFrB
-----END PGP SIGNATURE-----

?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 53201@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 53201
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help