Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/archivers/fastjar/files/patch-jartool.c
16461 views
1
--- jartool.c.orig 2025-02-09 11:28:36 UTC
2
+++ jartool.c
3
@@ -790,6 +790,7 @@ int read_entries (int fd)
4
progname, jarfile);
5
return 1;
6
}
7
+ ze->filename[len] = '\0';
8
len = UNPACK_UB4(header, CEN_EFLEN);
9
len += UNPACK_UB4(header, CEN_COMLEN);
10
if (lseek (fd, len, SEEK_CUR) == -1)
11
@@ -1257,7 +1258,7 @@ int add_file_to_jar(int jfd, int ffd, const char *fnam
12
exit_on_error("write");
13
14
/* write the file name to the zip file */
15
- if (1 == write(jfd, fname, file_name_length))
16
+ if (-1 == write(jfd, fname, file_name_length))
17
exit_on_error("write");
18
19
if(verbose){
20
@@ -1273,15 +1274,18 @@ int add_file_to_jar(int jfd, int ffd, const char *fnam
21
compress_file(ffd, jfd, ze, existing);
22
} else {
23
/* If we are not writing the last entry, make space for it. */
24
- if (existing && existing->next_entry)
25
+ if (existing)
26
{
27
- if (ze->usize > existing->usize)
28
+ if (existing->next_entry)
29
{
30
- if (shift_down (jfd, existing->next_entry->offset,
31
- ze->usize - existing->usize, existing->next_entry))
32
+ if (ze->usize > existing->usize)
33
{
34
- fprintf (stderr, "%s: %s\n", progname, strerror (errno));
35
- return 1;
36
+ if (shift_down (jfd, existing->next_entry->offset,
37
+ ze->usize - existing->usize, existing->next_entry))
38
+ {
39
+ fprintf (stderr, "%s: %s\n", progname, strerror (errno));
40
+ return 1;
41
+ }
42
}
43
}
44
}
45
@@ -1730,33 +1734,46 @@ int extract_jar(int fd, const char **files, int file_n
46
struct stat sbuf;
47
int depth = 0;
48
49
- tmp_buff = malloc(sizeof(char) * strlen((const char *)filename));
50
+ if(*filename == '/'){
51
+ fprintf(stderr, "Absolute path names are not allowed.\n");
52
+ exit(EXIT_FAILURE);
53
+ }
54
55
+ tmp_buff = malloc(strlen((const char *)filename));
56
+
57
+ if(tmp_buff == NULL) {
58
+ fprintf(stderr, "Out of memory.\n");
59
+ exit(EXIT_FAILURE);
60
+ }
61
+
62
for(;;){
63
const ub1 *idx = (const unsigned char *)strchr((const char *)start, '/');
64
65
if(idx == NULL)
66
break;
67
else if(idx == start){
68
+ tmp_buff[idx - filename] = '/';
69
start++;
70
continue;
71
}
72
- start = idx + 1;
73
74
- strncpy(tmp_buff, (const char *)filename, (idx - filename));
75
- tmp_buff[(idx - filename)] = '\0';
76
+ memcpy(tmp_buff + (start - filename), (const char *)start, (idx - start));
77
+ tmp_buff[idx - filename] = '\0';
78
79
#ifdef DEBUG
80
printf("checking the existance of %s\n", tmp_buff);
81
#endif
82
- if(strcmp(tmp_buff, "..") == 0){
83
+ if(idx - start == 2 && memcmp(start, "..", 2) == 0){
84
--depth;
85
if (depth < 0){
86
fprintf(stderr, "Traversal to parent directories during unpacking!\n");
87
exit(EXIT_FAILURE);
88
}
89
- } else if (strcmp(tmp_buff, ".") != 0)
90
+ } else if (idx - start != 1 || *start != '.')
91
++depth;
92
+
93
+ start = idx + 1;
94
+
95
if(stat(tmp_buff, &sbuf) < 0){
96
if(errno != ENOENT)
97
exit_on_error("stat");
98
@@ -1765,6 +1782,7 @@ int extract_jar(int fd, const char **files, int file_n
99
#ifdef DEBUG
100
printf("Directory exists\n");
101
#endif
102
+ tmp_buff[idx - filename] = '/';
103
continue;
104
}else {
105
fprintf(stderr, "Hmmm.. %s exists but isn't a directory!\n",
106
@@ -1781,10 +1799,11 @@ int extract_jar(int fd, const char **files, int file_n
107
if(verbose && handle)
108
printf("%10s: %s/\n", "created", tmp_buff);
109
110
+ tmp_buff[idx - filename] = '/';
111
}
112
113
/* only a directory */
114
- if(strlen((const char *)start) == 0)
115
+ if(*start == '\0')
116
dir = TRUE;
117
118
#ifdef DEBUG
119
@@ -1792,7 +1811,7 @@ int extract_jar(int fd, const char **files, int file_n
120
#endif
121
122
/* If the entry was just a directory, don't write to file, etc */
123
- if(strlen((const char *)start) == 0)
124
+ if(*start == '\0')
125
f_fd = -1;
126
127
free(tmp_buff);
128
@@ -1876,7 +1895,8 @@ int extract_jar(int fd, const char **files, int file_n
129
exit(EXIT_FAILURE);
130
}
131
132
- close(f_fd);
133
+ if (f_fd != -1)
134
+ close(f_fd);
135
136
if(verbose && dir == FALSE && handle)
137
printf("%10s: %s\n",
138
139