urlapi: verify the last letter of a scheme when set explictly

A logic error made the function not check the last character, which thus
could make it accept invalid schemes.

Added test 1965 to verify

Reported-by: Otis Cui Lei

Closes #20893
This commit is contained in:
Daniel Stenberg 2026-03-11 22:36:24 +01:00
parent 5fc7d50cec
commit 11c14b5ca5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 103 additions and 2 deletions

View file

@ -108,7 +108,7 @@ TESTS_C = \
lib1940.c lib1945.c \
lib1947.c lib1948.c \
lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c \
lib1964.c lib1970.c \
lib1964.c lib1965.c lib1970.c \
lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c \
lib2023.c lib2032.c lib2082.c \
lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c \

55
tests/libtest/lib1965.c Normal file
View file

@ -0,0 +1,55 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static CURLcode test_lib1965(const char *URL)
{
CURLcode result = CURLE_OK;
CURLUcode rc;
const char *schemes[] = {
"bad!", "bad{", "bad/", "bad\\", "a!",
"a+123", "http-2", "http.1",
"a+-.123", "http-+++2", "http.1--",
"+a123", "-http2", ".http1",
"ABC2", "2CBA", "", "a",
"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd",
"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddde",
NULL};
int i;
(void) URL;
global_init(CURL_GLOBAL_ALL);
for(i = 0; schemes[i]; i++) {
CURLU *url = curl_url();
rc = curl_url_set(url, CURLUPART_SCHEME, schemes[i],
CURLU_NON_SUPPORT_SCHEME);
curl_mprintf("%s %s\n", schemes[i],
rc == CURLUE_OK ? "ACCEPTED" : "REJECTED");
curl_url_cleanup(url);
}
curl_global_cleanup();
return result;
}