File: unit2604.c

package info (click to toggle)
curl 8.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,892 kB
  • sloc: ansic: 200,254; perl: 21,116; python: 10,390; sh: 6,691; makefile: 1,505; pascal: 240; cpp: 196
file content (115 lines) | stat: -rw-r--r-- 3,981 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***************************************************************************
 *                                  _   _ ____  _
 *  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 "vssh/vssh.h"

static CURLcode test_unit2604(const char *arg)
{
  UNITTEST_BEGIN_SIMPLE

#ifdef USE_SSH

  struct set {
    const char *cp;
    const char *expect; /* the returned content */
    const char *next;   /* what cp points to after the call */
    const char *home;
    CURLcode result;
  };

#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverlength-strings"
#endif

/* 60 a's */
#define SA60 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
/* 540 a's */
#define SA540 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60
  int i;
  const size_t too_long = 90720;
  struct set list[] = {
    { "-too-long-", "", "", "", CURLE_TOO_LARGE },
    { SA540 " c", SA540, "c", "/", CURLE_OK },
    { "\" " SA540 "\" c", " " SA540, "c", "/", CURLE_OK },
    { "a a", "a", "a", "/home/", CURLE_OK },
    { "b a", "b", "a", "/", CURLE_OK },
    { "a", "a", "", "/home/", CURLE_OK },
    { "b", "b", "", "/", CURLE_OK },
    { "\"foo bar\"\tb", "foo bar", "b", "/", CURLE_OK },
    { "/~/hej", "/home/user/hej", "", "/home/user", CURLE_OK },
    { "\"foo bar", "", "", "/", CURLE_QUOTE_ERROR },
    { "\"foo\\\"bar\" a", "foo\"bar", "a", "/", CURLE_OK },
    { "\"foo\\\'bar\" b", "foo\'bar", "b", "/", CURLE_OK },
    { "\"foo\\\\bar\" c", "foo\\bar", "c", "/", CURLE_OK },
    { "\"foo\\pbar\" c", "foo\\bar", "", "/", CURLE_QUOTE_ERROR },
    { "\"\" c", "", "", "", CURLE_QUOTE_ERROR },
    { "foo\"", "foo\"", "", "/", CURLE_OK },
    { "foo \"", "foo", "\"", "/", CURLE_OK },
    { "   \t\t   \t  ", "", "", "/", CURLE_QUOTE_ERROR },
    { "              ", "", "", "/", CURLE_QUOTE_ERROR },
    { "", "", "", "/", CURLE_QUOTE_ERROR },
    { "       \r \n  ", "\r", "\n  ", "/", CURLE_OK },
    { NULL, NULL, NULL, NULL, CURLE_OK }
  };

#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

  char *cp0 = curlx_calloc(1, too_long + 1);
  fail_unless(cp0, "could not alloc too long value");
  memset(cp0, 'a', too_long);

  for(i = 0; list[i].home; i++) {
    char *path;
    const char *cp = i == 0 ? cp0 : list[i].cp;
    CURLcode result = Curl_get_pathname(&cp, &path, list[i].home);
    curl_mprintf("%u - Curl_get_pathname(\"%s\", ... \"%s\") == %u\n", i,
                 list[i].cp, list[i].home, list[i].result);
    if(result != list[i].result) {
      curl_mprintf("... returned %d\n", result);
      unitfail++;
    }
    if(!result) {
      if(cp && strcmp(cp, list[i].next)) {
        curl_mprintf("... cp points to '%s', not '%s' as expected\n",
                     cp, list[i].next);
        unitfail++;
      }
      if(path && strcmp(path, list[i].expect)) {
        curl_mprintf("... gave '%s', not '%s' as expected\n",
                     path, list[i].expect);
        unitfail++;
      }
      curl_free(path);
    }
  }

  curlx_free(cp0);

#endif

  UNITTEST_END_SIMPLE
}