mirror of
https://github.com/curl/curl.git
synced 2026-08-25 01:33:31 +03:00
tool_dirhie: fix to create drive-relative directory
Fix to create the top directory `foo` when specified as
`X:foo\bar\filename`, on Windows and MS-DOS. Add test to verify.
Caught by Codex Security
Follow-up to 787ee935ac #16566
Closes #21449
This commit is contained in:
parent
e2f84e6ba9
commit
13b6a6036c
6 changed files with 133 additions and 7 deletions
|
|
@ -230,6 +230,7 @@ test1680 test1681 test1682 test1683 test1684 test1685 \
|
|||
\
|
||||
test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 \
|
||||
test1708 test1709 test1710 test1711 test1712 test1713 test1714 test1715 \
|
||||
test1720 \
|
||||
\
|
||||
test1800 test1801 test1802 test1847 test1848 test1849 test1850 test1851 \
|
||||
\
|
||||
|
|
|
|||
24
tests/data/test1720
Normal file
24
tests/data/test1720
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="US-ASCII"?>
|
||||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
unittest
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
# Client-side
|
||||
<client>
|
||||
<features>
|
||||
unittest
|
||||
</features>
|
||||
<name>
|
||||
create_dir_hierarchy()
|
||||
</name>
|
||||
<tool>
|
||||
tool%TESTNUMBER
|
||||
</tool>
|
||||
</client>
|
||||
|
||||
<verify>
|
||||
</verify>
|
||||
</testcase>
|
||||
|
|
@ -34,4 +34,5 @@ TESTS_C = \
|
|||
tool1604.c \
|
||||
tool1621.c \
|
||||
tool1622.c \
|
||||
tool1623.c
|
||||
tool1623.c \
|
||||
tool1720.c
|
||||
|
|
|
|||
79
tests/tunit/tool1720.c
Normal file
79
tests/tunit/tool1720.c
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* 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 "unitcheck.h"
|
||||
#include "tool_dirhie.h"
|
||||
|
||||
static CURLcode test_tool1720(const char *arg)
|
||||
{
|
||||
UNITTEST_BEGIN_SIMPLE
|
||||
|
||||
static const char *check[] = {
|
||||
"",
|
||||
"(null)",
|
||||
"filename",
|
||||
"(null)",
|
||||
"foo/bar/",
|
||||
"foo|foo/bar|",
|
||||
"foo/bar/filename",
|
||||
"foo|foo/bar|",
|
||||
"/foo/bar/filename",
|
||||
"/foo|/foo/bar|",
|
||||
#if defined(_WIN32) || defined(MSDOS)
|
||||
"C:/foo/bar/filename",
|
||||
"C:/foo|C:/foo/bar|",
|
||||
"C:foo/bar/filename",
|
||||
"C:foo|C:foo/bar|",
|
||||
"foo\\bar\\filename",
|
||||
"foo|foo\\bar|",
|
||||
"\\foo\\bar\\filename",
|
||||
"\\foo|\\foo\\bar|",
|
||||
"C:\\foo\\bar\\filename",
|
||||
"C:\\foo|C:\\foo\\bar|",
|
||||
"C:foo\\bar\\filename",
|
||||
"C:foo|C:foo\\bar|",
|
||||
#endif
|
||||
};
|
||||
|
||||
size_t i;
|
||||
struct dynbuf *res = create_dir_hierarchy_trace_dynres();
|
||||
|
||||
curlx_dyn_init(res, 256);
|
||||
|
||||
for(i = 0; i < CURL_ARRAYSIZE(check); i += 2) {
|
||||
const char *actual;
|
||||
curlx_dyn_reset(res);
|
||||
create_dir_hierarchy(check[i]);
|
||||
actual = curlx_dyn_ptr(res);
|
||||
if(!actual)
|
||||
actual = "(null)";
|
||||
if(strcmp(check[i + 1], actual)) {
|
||||
curl_mprintf("Expected '%s' got '%s'\n", check[i + 1], actual);
|
||||
unitfail++;
|
||||
}
|
||||
}
|
||||
|
||||
curlx_dyn_free(res);
|
||||
|
||||
UNITTEST_END_SIMPLE
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue