Debian Codegraph @

t_clean_fname.c

raw symbols SCIP
1 /* Unit test for KI-50: clean_fname(name, CFN_COLLAPSE_DOT_DOT_DIRS) must
2 * collapse ".." components. An off-by-one left the collapse dead for all
3 * multi-component and absolute paths. Exits 0 if all cases collapse correctly,
4 * 1 otherwise. */
5
6 #define main rsync_main
7 #include "rsync.h"
8 #undef main
9
10 #include <stdio.h>
11
12 /* Globals referenced by syscall.o/util1.o (mirrors t_unsafe.c). */
13 int dry_run = 0, am_root = 0, am_sender = 1, read_only = 0, list_only = 0;
14 int copy_links = 0, copy_unsafe_links = 0;
15 short info_levels[COUNT_INFO], debug_levels[COUNT_DEBUG];
16
17 static const struct { const char *in, *out; } cases[] = {
18 { "a/b/../c", "a/c" },
19 { "/x/y/../z", "/x/z" },
20 { "a/../b", "b" },
21 { "p/q/r/../../s","p/s" },
22 { "d/e/..", "d" },
23 };
24
25 int main(int argc, char *argv[])
26 {
27 (void)argc; (void)argv;
28 int i, fails = 0, n = (int)(sizeof cases / sizeof cases[0]);
29 for (i = 0; i < n; i++) {
30 char buf[MAXPATHLEN];
31 strlcpy(buf, cases[i].in, sizeof buf);
32 clean_fname(buf, CFN_COLLAPSE_DOT_DOT_DIRS);
33 if (strcmp(buf, cases[i].out) != 0) {
34 printf("FAIL: clean_fname(\"%s\") = \"%s\", expected \"%s\"\n",
35 cases[i].in, buf, cases[i].out);
36 fails++;
37 }
38 }
39 if (fails) {
40 printf("clean_fname: %d case(s) not collapsed -- CFN_COLLAPSE_DOT_DOT_DIRS "
41 "off-by-one\n", fails);
42 return 1;
43 }
44 printf("clean_fname: '..' collapse correct\n");
45 return 0;
46 }