git: 766ee52dc964 - stable/14 - libfetch: Reject control characters in credentials

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Thu, 05 Nov 2026 15:12:32 UTC
The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=766ee52dc9647bd977a6a9f54e8ae22404cf71ff

commit 766ee52dc9647bd977a6a9f54e8ae22404cf71ff
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-30 16:54:33 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-05 15:11:57 +0000

    libfetch: Reject control characters in credentials
    
    If a URL contains credentials, check that neither the user name nor the
    password contain control characters which might confuse the server,
    especially in the FTP case.
    
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D60008
    
    (cherry picked from commit b319c3d6ac7cf408b56fe745f718de6a324ec180)
---
 lib/libfetch/fetch.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c
index 6e14a62ca596..c00e6721bbbc 100644
--- a/lib/libfetch/fetch.c
+++ b/lib/libfetch/fetch.c
@@ -348,7 +348,7 @@ struct url *
 fetchParseURL(const char *URL)
 {
 	char *doc;
-	const char *p, *q;
+	const char *p, *q, *r;
 	struct url *u;
 	int i, n;
 
@@ -386,12 +386,18 @@ fetchParseURL(const char *URL)
 		q = fetch_pctdecode(u->user, URL, URL_USERLEN);
 		if (q == NULL)
 			goto ouch;
+		for (r = u->user; *r != '\0'; r++)
+			if (iscntrl((unsigned char)*r))
+				goto ouch;
 
 		/* password */
 		if (*q == ':') {
 			q = fetch_pctdecode(u->pwd, q + 1, URL_PWDLEN);
 			if (q == NULL)
 				goto ouch;
+			for (r = u->pwd; *r != '\0'; r++)
+				if (iscntrl((unsigned char)*r))
+					goto ouch;
 		}
 		p++;
 	} else {