1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24 #include "curlcheck.h"
25 #include "vssh/curl_path.h"
26 #include "memdebug.h"
27
unit_setup(void)28 static CURLcode unit_setup(void)
29 {
30 return CURLE_OK;
31 }
32
unit_stop(void)33 static void unit_stop(void)
34 {
35 }
36
37
38 struct set {
39 const char *cp;
40 const char *expect; /* the returned content */
41 const char *next; /* what cp points to after the call */
42 const char *home;
43 CURLcode result;
44 };
45
46 UNITTEST_START
47 #ifdef USE_SSH
48 {
49 #if defined(__GNUC__) || defined(__clang__)
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Woverlength-strings"
52 #endif
53
54 /* 60 a's */
55 #define SA60 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
56 /* 540 a's */
57 #define SA540 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60
58 int i;
59 size_t too_long = 90720;
60 struct set list[] = {
61 { "-too-long-", "", "", "", CURLE_TOO_LARGE},
62 { SA540 " c", SA540, "c", "/", CURLE_OK},
63 { "\" " SA540 "\" c", " " SA540, "c", "/", CURLE_OK},
64 { "a a", "a", "a", "/home/", CURLE_OK},
65 { "b a", "b", "a", "/", CURLE_OK},
66 { "a", "a", "", "/home/", CURLE_OK},
67 { "b", "b", "", "/", CURLE_OK},
68 { "\"foo bar\"\tb", "foo bar", "b", "/", CURLE_OK},
69 { "/~/hej", "/home/user/hej", "", "/home/user", CURLE_OK},
70 { "\"foo bar", "", "", "/", CURLE_QUOTE_ERROR},
71 { "\"foo\\\"bar\" a", "foo\"bar", "a", "/", CURLE_OK},
72 { "\"foo\\\'bar\" b", "foo\'bar", "b", "/", CURLE_OK},
73 { "\"foo\\\\bar\" c", "foo\\bar", "c", "/", CURLE_OK},
74 { "\"foo\\pbar\" c", "foo\\bar", "", "/", CURLE_QUOTE_ERROR},
75 { "\"\" c", "", "", "", CURLE_QUOTE_ERROR},
76 { "foo\"", "foo\"", "", "/", CURLE_OK},
77 { "foo \"", "foo", "\"", "/", CURLE_OK},
78 { NULL, NULL, NULL, NULL, CURLE_OK }
79 };
80
81 #if defined(__GNUC__) || defined(__clang__)
82 #pragma GCC diagnostic warning "-Woverlength-strings"
83 #endif
84
85 list[0].cp = calloc(1, too_long + 1);
86 fail_unless(list[0].cp, "could not alloc too long value");
87 memset((void *)list[0].cp, 'a', too_long);
88
89 for(i = 0; list[i].home; i++) {
90 char *path;
91 const char *cp = list[i].cp;
92 CURLcode result = Curl_get_pathname(&cp, &path, list[i].home);
93 printf("%u - Curl_get_pathname(\"%s\", ... \"%s\") == %u\n", i,
94 list[i].cp, list[i].home, list[i].result);
95 if(result != list[i].result) {
96 printf("... returned %d\n", result);
97 unitfail++;
98 }
99 if(!result) {
100 if(cp && strcmp(cp, list[i].next)) {
101 printf("... cp points to '%s', not '%s' as expected \n",
102 cp, list[i].next);
103 unitfail++;
104 }
105 if(path && strcmp(path, list[i].expect)) {
106 printf("... gave '%s', not '%s' as expected \n",
107 path, list[i].expect);
108 unitfail++;
109 }
110 curl_free(path);
111
112 }
113 }
114
115 free((void *)list[0].cp);
116 }
117 #if defined(__GNUC__) || defined(__clang__)
118 #pragma GCC diagnostic pop
119 #endif
120
121 #endif
122
123 UNITTEST_STOP
124