Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/archivers/lha/files/patch-lhext.c
16147 views
1
--- src/lhext.c.orig 2000-10-04 14:57:38 UTC
2
+++ src/lhext.c
3
@@ -143,13 +143,13 @@ adjust_info(name, hdr)
4
char *name;
5
LzHeader *hdr;
6
{
7
- time_t utimebuf[2];
8
+ struct utimbuf utimebuf;
9
10
/* adjust file stamp */
11
- utimebuf[0] = utimebuf[1] = hdr->unix_last_modified_stamp;
12
+ utimebuf.actime = utimebuf.modtime = hdr->unix_last_modified_stamp;
13
14
if ((hdr->unix_mode & UNIX_FILE_TYPEMASK) != UNIX_FILE_SYMLINK)
15
- utime(name, utimebuf);
16
+ utime(name, &utimebuf);
17
18
if (hdr->extend_type == EXTEND_UNIX
19
|| hdr->extend_type == EXTEND_OS68K
20
@@ -190,8 +190,13 @@ extract_one(afp, hdr)
21
q = (char *) rindex(hdr->name, '/') + 1;
22
}
23
else {
24
+ if (is_directory_traversal(q)) {
25
+ fprintf(stderr, "Possible directory traversal hack attempt in %s\n", q);
26
+ exit(111);
27
+ }
28
+
29
if (*q == '/') {
30
- q++;
31
+ while (*q == '/') { q++; }
32
/*
33
* if OSK then strip device name
34
*/
35
@@ -351,10 +356,13 @@ extract_one(afp, hdr)
36
}
37
38
unlink(bb1);
39
+ make_parent_path(bb1);
40
l_code = symlink(bb2, bb1);
41
if (l_code < 0) {
42
- if (quiet != TRUE)
43
- warning("Can't make Symbolic Link : ");
44
+ if (quiet != TRUE) {
45
+ sprintf(buf, "%s -> %s", bb1, bb2);
46
+ warning("Can't make Symbolic Link : ", buf);
47
+ }
48
}
49
if (quiet != TRUE) {
50
printf("Symbolic Link %s -> %s\n", bb1, bb2);
51
@@ -419,6 +427,33 @@ cmd_extract()
52
return;
53
}
54
55
+int
56
+is_directory_traversal(char *string)
57
+{
58
+ unsigned int type = 0; /* 0 = new, 1 = only dots, 2 = other chars than dots */
59
+ char *temp;
60
+
61
+ temp = string;
62
+
63
+ while (*temp != 0) {
64
+ if (temp[0] == '/') {
65
+ if (type == 1) { return 1; }
66
+ type = 0;
67
+ temp++;
68
+ continue;
69
+ }
70
+
71
+ if ((temp[0] == '.') && (type < 2))
72
+ type = 1;
73
+ if (temp[0] != '.')
74
+ type = 2;
75
+
76
+ temp++;
77
+ } /* while */
78
+
79
+ return (type == 1);
80
+}
81
+
82
/* Local Variables: */
83
/* mode:c */
84
/* tab-width:4 */
85
86