Lines 21-44
Link Here
|
21 |
# include <string.h> |
21 |
# include <string.h> |
22 |
#endif |
22 |
#endif |
23 |
|
23 |
|
|
|
24 |
char * |
25 |
safer_name_suffix (char const *file_name) |
26 |
{ |
27 |
char const *p, *t; |
28 |
p = t = file_name; |
29 |
while (*p) |
30 |
{ |
31 |
if (p[0] == '.' && p[0] == p[1] && p[2] == '/') |
32 |
{ |
33 |
p += 3; |
34 |
t = p; |
35 |
} |
36 |
/* advance pointer past the next slash */ |
37 |
while (*p && (p++)[0] != '/'); |
38 |
} |
39 |
|
40 |
if (!*t) |
41 |
{ |
42 |
t = "."; |
43 |
} |
44 |
|
45 |
if (t != file_name) |
46 |
{ |
47 |
/* TODO: warn somehow that the path was modified */ |
48 |
} |
49 |
return (char*)t; |
50 |
} |
51 |
|
24 |
|
52 |
|
25 |
/* determine full path name */ |
53 |
/* determine full path name */ |
26 |
char * |
54 |
char * |
27 |
th_get_pathname(TAR *t) |
55 |
th_get_pathname(TAR *t) |
28 |
{ |
56 |
{ |
29 |
static TLS_THREAD char filename[MAXPATHLEN]; |
57 |
static TLS_THREAD char filename[MAXPATHLEN]; |
|
|
58 |
char *safer_name; |
30 |
|
59 |
|
31 |
if (t->th_buf.gnu_longname) |
60 |
if (t->th_buf.gnu_longname) |
32 |
return t->th_buf.gnu_longname; |
61 |
return safer_name_suffix(t->th_buf.gnu_longname); |
|
|
62 |
|
63 |
safer_name = safer_name_suffix(t->th_buf.name); |
33 |
|
64 |
|
34 |
if (t->th_buf.prefix[0] != '\0') |
65 |
if (t->th_buf.prefix[0] != '\0') |
35 |
{ |
66 |
{ |
36 |
snprintf(filename, sizeof(filename), "%.155s/%.100s", |
67 |
snprintf(filename, sizeof(filename), "%.155s/%.100s", |
37 |
t->th_buf.prefix, t->th_buf.name); |
68 |
t->th_buf.prefix, safer_name); |
38 |
return filename; |
69 |
return filename; |
39 |
} |
70 |
} |
40 |
|
71 |
|
41 |
snprintf(filename, sizeof(filename), "%.100s", t->th_buf.name); |
72 |
snprintf(filename, sizeof(filename), "%.100s", safer_name); |
42 |
return filename; |
73 |
return filename; |
43 |
} |
74 |
} |
44 |
|
75 |
|