unit2604.c (3748B)
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 "unitcheck.h" 25 #include "vssh/curl_path.h" 26 #include "memdebug.h" 27 28 static CURLcode test_unit2604(char *arg) 29 { 30 UNITTEST_BEGIN_SIMPLE 31 32 #ifdef USE_SSH 33 34 struct set { 35 const char *cp; 36 const char *expect; /* the returned content */ 37 const char *next; /* what cp points to after the call */ 38 const char *home; 39 CURLcode result; 40 }; 41 42 #if defined(CURL_GNUC_DIAG) || defined(__clang__) 43 #pragma GCC diagnostic push 44 #pragma GCC diagnostic ignored "-Woverlength-strings" 45 #endif 46 47 /* 60 a's */ 48 #define SA60 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 49 /* 540 a's */ 50 #define SA540 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60 51 int i; 52 size_t too_long = 90720; 53 struct set list[] = { 54 { "-too-long-", "", "", "", CURLE_TOO_LARGE}, 55 { SA540 " c", SA540, "c", "/", CURLE_OK}, 56 { "\" " SA540 "\" c", " " SA540, "c", "/", CURLE_OK}, 57 { "a a", "a", "a", "/home/", CURLE_OK}, 58 { "b a", "b", "a", "/", CURLE_OK}, 59 { "a", "a", "", "/home/", CURLE_OK}, 60 { "b", "b", "", "/", CURLE_OK}, 61 { "\"foo bar\"\tb", "foo bar", "b", "/", CURLE_OK}, 62 { "/~/hej", "/home/user/hej", "", "/home/user", CURLE_OK}, 63 { "\"foo bar", "", "", "/", CURLE_QUOTE_ERROR}, 64 { "\"foo\\\"bar\" a", "foo\"bar", "a", "/", CURLE_OK}, 65 { "\"foo\\\'bar\" b", "foo\'bar", "b", "/", CURLE_OK}, 66 { "\"foo\\\\bar\" c", "foo\\bar", "c", "/", CURLE_OK}, 67 { "\"foo\\pbar\" c", "foo\\bar", "", "/", CURLE_QUOTE_ERROR}, 68 { "\"\" c", "", "", "", CURLE_QUOTE_ERROR}, 69 { "foo\"", "foo\"", "", "/", CURLE_OK}, 70 { "foo \"", "foo", "\"", "/", CURLE_OK}, 71 { NULL, NULL, NULL, NULL, CURLE_OK } 72 }; 73 74 #if defined(CURL_GNUC_DIAG) || defined(__clang__) 75 #pragma GCC diagnostic pop 76 #endif 77 78 list[0].cp = calloc(1, too_long + 1); 79 fail_unless(list[0].cp, "could not alloc too long value"); 80 memset(CURL_UNCONST(list[0].cp), 'a', too_long); 81 82 for(i = 0; list[i].home; i++) { 83 char *path; 84 const char *cp = list[i].cp; 85 CURLcode result = Curl_get_pathname(&cp, &path, list[i].home); 86 printf("%u - Curl_get_pathname(\"%s\", ... \"%s\") == %u\n", i, 87 list[i].cp, list[i].home, list[i].result); 88 if(result != list[i].result) { 89 printf("... returned %d\n", result); 90 unitfail++; 91 } 92 if(!result) { 93 if(cp && strcmp(cp, list[i].next)) { 94 printf("... cp points to '%s', not '%s' as expected \n", 95 cp, list[i].next); 96 unitfail++; 97 } 98 if(path && strcmp(path, list[i].expect)) { 99 printf("... gave '%s', not '%s' as expected \n", 100 path, list[i].expect); 101 unitfail++; 102 } 103 curl_free(path); 104 105 } 106 } 107 108 free(CURL_UNCONST(list[0].cp)); 109 110 #endif 111 112 UNITTEST_END_SIMPLE 113 }