unit2604.c 3.8 KB

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