author | ihse |
Sat, 03 Mar 2018 08:21:47 +0100 | |
branch | ihse-warnings-cflags-branch |
changeset 56230 | 489867818774 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29742
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <sys/types.h> |
|
27 |
#include <sys/stat.h> |
|
28 |
#include <fcntl.h> |
|
29 |
#include <stdio.h> |
|
30 |
#include <stdlib.h> |
|
31 |
#include <string.h> |
|
32 |
#include "jli_util.h" |
|
33 |
||
34 |
#include <zlib.h> |
|
35 |
#include "manifest_info.h" |
|
36 |
||
37 |
static char *manifest; |
|
38 |
||
39 |
static const char *manifest_name = "META-INF/MANIFEST.MF"; |
|
40 |
||
41 |
/* |
|
42 |
* Inflate the manifest file (or any file for that matter). |
|
43 |
* |
|
44 |
* fd: File descriptor of the jar file. |
|
45 |
* entry: Contains the information necessary to perform the inflation |
|
46 |
* (the compressed and uncompressed sizes and the offset in |
|
47 |
* the file where the compressed data is located). |
|
48 |
* size_out: Returns the size of the inflated file. |
|
49 |
* |
|
50 |
* Upon success, it returns a pointer to a NUL-terminated malloc'd buffer |
|
51 |
* containing the inflated manifest file. When the caller is done with it, |
|
52 |
* this buffer should be released by a call to free(). Upon failure, |
|
53 |
* returns NULL. |
|
54 |
*/ |
|
55 |
static char * |
|
56 |
inflate_file(int fd, zentry *entry, int *size_out) |
|
57 |
{ |
|
58 |
char *in; |
|
59 |
char *out; |
|
60 |
z_stream zs; |
|
61 |
||
3848
2c2395fb6d85
6842838: 64-bit failure in handling invalid manifest in launcher.
kevinw
parents:
2
diff
changeset
|
62 |
if (entry->csize == (size_t) -1 || entry->isize == (size_t) -1 ) |
2 | 63 |
return (NULL); |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
64 |
if (JLI_Lseek(fd, entry->offset, SEEK_SET) < (jlong)0) |
2 | 65 |
return (NULL); |
66 |
if ((in = malloc(entry->csize + 1)) == NULL) |
|
67 |
return (NULL); |
|
68 |
if ((size_t)(read(fd, in, (unsigned int)entry->csize)) != entry->csize) { |
|
69 |
free(in); |
|
70 |
return (NULL); |
|
71 |
} |
|
72 |
if (entry->how == STORED) { |
|
73 |
*(char *)((size_t)in + entry->csize) = '\0'; |
|
74 |
if (size_out) { |
|
7028
adadd244f506
6989469: (launcher) compiler warnings in jli native code
ksrini
parents:
5506
diff
changeset
|
75 |
*size_out = (int)entry->csize; |
2 | 76 |
} |
77 |
return (in); |
|
78 |
} else if (entry->how == DEFLATED) { |
|
79 |
zs.zalloc = (alloc_func)Z_NULL; |
|
80 |
zs.zfree = (free_func)Z_NULL; |
|
81 |
zs.opaque = (voidpf)Z_NULL; |
|
82 |
zs.next_in = (Byte*)in; |
|
83 |
zs.avail_in = (uInt)entry->csize; |
|
84 |
if (inflateInit2(&zs, -MAX_WBITS) < 0) { |
|
85 |
free(in); |
|
86 |
return (NULL); |
|
87 |
} |
|
88 |
if ((out = malloc(entry->isize + 1)) == NULL) { |
|
89 |
free(in); |
|
90 |
return (NULL); |
|
91 |
} |
|
92 |
zs.next_out = (Byte*)out; |
|
93 |
zs.avail_out = (uInt)entry->isize; |
|
94 |
if (inflate(&zs, Z_PARTIAL_FLUSH) < 0) { |
|
95 |
free(in); |
|
96 |
free(out); |
|
97 |
return (NULL); |
|
98 |
} |
|
99 |
*(char *)((size_t)out + entry->isize) = '\0'; |
|
100 |
free(in); |
|
101 |
if (inflateEnd(&zs) < 0) { |
|
102 |
free(out); |
|
103 |
return (NULL); |
|
104 |
} |
|
105 |
if (size_out) { |
|
7028
adadd244f506
6989469: (launcher) compiler warnings in jli native code
ksrini
parents:
5506
diff
changeset
|
106 |
*size_out = (int)entry->isize; |
2 | 107 |
} |
108 |
return (out); |
|
15668
c5d8a90a4b40
8005750: [parfait] Memory leak at jdk/src/share/bin/parse_manifest.c
ksrini
parents:
15644
diff
changeset
|
109 |
} |
c5d8a90a4b40
8005750: [parfait] Memory leak at jdk/src/share/bin/parse_manifest.c
ksrini
parents:
15644
diff
changeset
|
110 |
free(in); |
c5d8a90a4b40
8005750: [parfait] Memory leak at jdk/src/share/bin/parse_manifest.c
ksrini
parents:
15644
diff
changeset
|
111 |
return (NULL); |
2 | 112 |
} |
113 |
||
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
114 |
/* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
115 |
* Implementation notes: |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
116 |
* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
117 |
* This is a zip format reader for seekable files, that tolerates |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
118 |
* leading and trailing garbage, and tolerates having had internal |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
119 |
* offsets adjusted for leading garbage (as with Info-Zip's zip -A). |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
120 |
* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
121 |
* We find the end header by scanning backwards from the end of the |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
122 |
* file for the end signature. This may fail in the presence of |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
123 |
* trailing garbage or a ZIP file comment that contains binary data. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
124 |
* Similarly, the ZIP64 end header may need to be located by scanning |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
125 |
* backwards from the end header. It may be misidentified, but this |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
126 |
* is very unlikely to happen in practice without adversarial input. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
127 |
* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
128 |
* The zip file format is documented at: |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
129 |
* https://www.pkware.com/documents/casestudies/APPNOTE.TXT |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
130 |
* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
131 |
* TODO: more informative error messages |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
132 |
*/ |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
133 |
|
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
134 |
/** Reads count bytes from fd at position pos into given buffer. */ |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
135 |
static jboolean |
29742
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
136 |
readAt(int fd, jlong pos, unsigned int count, void *buf) { |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
137 |
return (pos >= 0 |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
138 |
&& JLI_Lseek(fd, pos, SEEK_SET) == pos |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
139 |
&& read(fd, buf, count) == (jlong) count); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
140 |
} |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
141 |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
142 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
143 |
/* |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
144 |
* Tells whether given header values (obtained from either ZIP64 or |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
145 |
* non-ZIP64 header) appear to be correct, by checking the first LOC |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
146 |
* and CEN headers. |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
147 |
*/ |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
148 |
static jboolean |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
149 |
is_valid_end_header(int fd, jlong endpos, |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
150 |
jlong censiz, jlong cenoff, jlong entries) { |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
151 |
Byte cenhdr[CENHDR]; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
152 |
Byte lochdr[LOCHDR]; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
153 |
// Expected offset of the first central directory header |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
154 |
jlong censtart = endpos - censiz; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
155 |
// Expected position within the file that offsets are relative to |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
156 |
jlong base_offset = endpos - (censiz + cenoff); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
157 |
return censtart >= 0 && cenoff >= 0 && |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
158 |
(censiz == 0 || |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
159 |
// Validate first CEN and LOC header signatures. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
160 |
// Central directory must come directly before the end header. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
161 |
(readAt(fd, censtart, CENHDR, cenhdr) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
162 |
&& CENSIG_AT(cenhdr) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
163 |
&& readAt(fd, base_offset + CENOFF(cenhdr), LOCHDR, lochdr) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
164 |
&& LOCSIG_AT(lochdr) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
165 |
&& CENNAM(cenhdr) == LOCNAM(lochdr))); |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
166 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
167 |
|
2 | 168 |
/* |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
169 |
* Tells whether p appears to be pointing at a valid ZIP64 end header. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
170 |
* Values censiz, cenoff, and entries are the corresponding values |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
171 |
* from the non-ZIP64 end header. We perform extra checks to avoid |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
172 |
* misidentifying data from the last entry as a ZIP64 end header. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
173 |
*/ |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
174 |
static jboolean |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
175 |
is_zip64_endhdr(int fd, const Byte *p, jlong end64pos, |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
176 |
jlong censiz, jlong cenoff, jlong entries) { |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
177 |
if (ZIP64_ENDSIG_AT(p)) { |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
178 |
jlong censiz64 = ZIP64_ENDSIZ(p); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
179 |
jlong cenoff64 = ZIP64_ENDOFF(p); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
180 |
jlong entries64 = ZIP64_ENDTOT(p); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
181 |
return (censiz64 == censiz || censiz == ZIP64_MAGICVAL) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
182 |
&& (cenoff64 == cenoff || cenoff == ZIP64_MAGICVAL) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
183 |
&& (entries64 == entries || entries == ZIP64_MAGICCOUNT) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
184 |
&& is_valid_end_header(fd, end64pos, censiz64, cenoff64, entries64); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
185 |
} |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
186 |
return JNI_FALSE; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
187 |
} |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
188 |
|
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
189 |
/* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
190 |
* Given a non-ZIP64 end header located at endhdr and endpos, look for |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
191 |
* an adjacent ZIP64 end header, finding the base offset and censtart |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
192 |
* from the ZIP64 header if available, else from the non-ZIP64 header. |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
193 |
* @return 0 if successful, -1 in case of failure |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
194 |
*/ |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
195 |
static int |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
196 |
find_positions64(int fd, const Byte * const endhdr, const jlong endpos, |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
197 |
jlong* base_offset, jlong* censtart) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
198 |
{ |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
199 |
jlong censiz = ENDSIZ(endhdr); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
200 |
jlong cenoff = ENDOFF(endhdr); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
201 |
jlong entries = ENDTOT(endhdr); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
202 |
jlong end64pos; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
203 |
Byte buf[ZIP64_ENDHDR + ZIP64_LOCHDR]; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
204 |
if (censiz + cenoff != endpos |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
205 |
&& (end64pos = endpos - sizeof(buf)) >= (jlong)0 |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
206 |
&& readAt(fd, end64pos, sizeof(buf), buf) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
207 |
&& ZIP64_LOCSIG_AT(buf + ZIP64_ENDHDR) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
208 |
&& (jlong) ZIP64_LOCDSK(buf + ZIP64_ENDHDR) == ENDDSK(endhdr) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
209 |
&& (is_zip64_endhdr(fd, buf, end64pos, censiz, cenoff, entries) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
210 |
|| // A variable sized "zip64 extensible data sector" ? |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
211 |
((end64pos = ZIP64_LOCOFF(buf + ZIP64_ENDHDR)) >= (jlong)0 |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
212 |
&& readAt(fd, end64pos, ZIP64_ENDHDR, buf) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
213 |
&& is_zip64_endhdr(fd, buf, end64pos, censiz, cenoff, entries))) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
214 |
) { |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
215 |
*censtart = end64pos - ZIP64_ENDSIZ(buf); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
216 |
*base_offset = *censtart - ZIP64_ENDOFF(buf); |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
217 |
} else { |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
218 |
if (!is_valid_end_header(fd, endpos, censiz, cenoff, entries)) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
219 |
return -1; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
220 |
*censtart = endpos - censiz; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
221 |
*base_offset = *censtart - cenoff; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
222 |
} |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
223 |
return 0; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
224 |
} |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
225 |
|
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
226 |
/* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
227 |
* Finds the base offset and censtart of the zip file. |
2 | 228 |
* |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
229 |
* @param fd file descriptor of the jar file |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
230 |
* @param eb scratch buffer |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
231 |
* @return 0 if successful, -1 in case of failure |
2 | 232 |
*/ |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
233 |
static int |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
234 |
find_positions(int fd, Byte *eb, jlong* base_offset, jlong* censtart) |
2 | 235 |
{ |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
236 |
jlong len; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
237 |
jlong pos; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
238 |
jlong flen; |
2 | 239 |
int bytes; |
240 |
Byte *cp; |
|
241 |
Byte *endpos; |
|
242 |
Byte *buffer; |
|
243 |
||
244 |
/* |
|
245 |
* 99.44% (or more) of the time, there will be no comment at the |
|
246 |
* end of the zip file. Try reading just enough to read the END |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
247 |
* record from the end of the file, at this time we should also |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
248 |
* check to see if we have a ZIP64 archive. |
2 | 249 |
*/ |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
250 |
if ((pos = JLI_Lseek(fd, -ENDHDR, SEEK_END)) < (jlong)0) |
2 | 251 |
return (-1); |
29742
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
252 |
if (read(fd, eb, ENDHDR) < 0) |
2 | 253 |
return (-1); |
29389
348a32f79d79
8074579: Use more efficient and readable way of checking PKZIP signatures
martin
parents:
27938
diff
changeset
|
254 |
if (ENDSIG_AT(eb)) { |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
255 |
return find_positions64(fd, eb, pos, base_offset, censtart); |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
256 |
} |
2 | 257 |
|
258 |
/* |
|
259 |
* Shucky-Darn,... There is a comment at the end of the zip file. |
|
260 |
* |
|
261 |
* Allocate and fill a buffer with enough of the zip file |
|
262 |
* to meet the specification for a maximal comment length. |
|
263 |
*/ |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
264 |
if ((flen = JLI_Lseek(fd, 0, SEEK_END)) < (jlong)0) |
2 | 265 |
return (-1); |
266 |
len = (flen < END_MAXLEN) ? flen : END_MAXLEN; |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
267 |
if (JLI_Lseek(fd, -len, SEEK_END) < (jlong)0) |
2 | 268 |
return (-1); |
269 |
if ((buffer = malloc(END_MAXLEN)) == NULL) |
|
270 |
return (-1); |
|
29742
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
271 |
|
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
272 |
/* |
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
273 |
* read() on windows takes an unsigned int for count. Casting len |
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
274 |
* to an unsigned int here is safe since it is guaranteed to be |
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
275 |
* less than END_MAXLEN. |
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
276 |
*/ |
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
277 |
if ((bytes = read(fd, buffer, (unsigned int)len)) < 0) { |
2 | 278 |
free(buffer); |
279 |
return (-1); |
|
280 |
} |
|
281 |
||
282 |
/* |
|
283 |
* Search backwards from the end of file stopping when the END header |
|
29389
348a32f79d79
8074579: Use more efficient and readable way of checking PKZIP signatures
martin
parents:
27938
diff
changeset
|
284 |
* signature is found. |
2 | 285 |
*/ |
286 |
endpos = &buffer[bytes]; |
|
287 |
for (cp = &buffer[bytes - ENDHDR]; cp >= &buffer[0]; cp--) |
|
29389
348a32f79d79
8074579: Use more efficient and readable way of checking PKZIP signatures
martin
parents:
27938
diff
changeset
|
288 |
if (ENDSIG_AT(cp) && (cp + ENDHDR + ENDCOM(cp) == endpos)) { |
2 | 289 |
(void) memcpy(eb, cp, ENDHDR); |
290 |
free(buffer); |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
291 |
pos = flen - (endpos - cp); |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
292 |
return find_positions64(fd, eb, pos, base_offset, censtart); |
2 | 293 |
} |
294 |
free(buffer); |
|
295 |
return (-1); |
|
296 |
} |
|
297 |
||
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
298 |
#define BUFSIZE (3 * 65536 + CENHDR + SIGSIZ) |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
299 |
#define MINREAD 1024 |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
300 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
301 |
/* |
2 | 302 |
* Locate the manifest file with the zip/jar file. |
303 |
* |
|
304 |
* fd: File descriptor of the jar file. |
|
305 |
* entry: To be populated with the information necessary to perform |
|
306 |
* the inflation (the compressed and uncompressed sizes and |
|
307 |
* the offset in the file where the compressed data is located). |
|
308 |
* |
|
309 |
* Returns zero upon success. Returns a negative value upon failure. |
|
310 |
* |
|
311 |
* The buffer for reading the Central Directory if the zip/jar file needs |
|
312 |
* to be large enough to accommodate the largest possible single record |
|
313 |
* and the signature of the next record which is: |
|
314 |
* |
|
315 |
* 3*2**16 + CENHDR + SIGSIZ |
|
316 |
* |
|
317 |
* Each of the three variable sized fields (name, comment and extension) |
|
318 |
* has a maximum possible size of 64k. |
|
319 |
* |
|
320 |
* Typically, only a small bit of this buffer is used with bytes shuffled |
|
321 |
* down to the beginning of the buffer. It is one thing to allocate such |
|
322 |
* a large buffer and another thing to actually start faulting it in. |
|
323 |
* |
|
324 |
* In most cases, all that needs to be read are the first two entries in |
|
325 |
* a typical jar file (META-INF and META-INF/MANIFEST.MF). Keep this factoid |
|
326 |
* in mind when optimizing this code. |
|
327 |
*/ |
|
328 |
static int |
|
329 |
find_file(int fd, zentry *entry, const char *file_name) |
|
330 |
{ |
|
331 |
int bytes; |
|
332 |
int res; |
|
333 |
int entry_size; |
|
334 |
int read_size; |
|
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
335 |
|
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
336 |
/* |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
337 |
* The (imaginary) position within the file relative to which |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
338 |
* offsets within the zip file refer. This is usually the |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
339 |
* location of the first local header (the start of the zip data) |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
340 |
* (which in turn is usually 0), but if the zip file has content |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
341 |
* prepended, then it will be either 0 or the length of the |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
342 |
* prepended content, depending on whether or not internal offsets |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
343 |
* have been adjusted (via e.g. zip -A). May be negative if |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
344 |
* content is prepended, zip -A is run, then the prefix is |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
345 |
* detached! |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
346 |
*/ |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
347 |
jlong base_offset; |
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
348 |
|
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
349 |
/** The position within the file of the start of the central directory. */ |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
350 |
jlong censtart; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
351 |
|
2 | 352 |
Byte *p; |
353 |
Byte *bp; |
|
354 |
Byte *buffer; |
|
355 |
Byte locbuf[LOCHDR]; |
|
356 |
||
357 |
if ((buffer = (Byte*)malloc(BUFSIZE)) == NULL) { |
|
358 |
return(-1); |
|
359 |
} |
|
360 |
||
361 |
bp = buffer; |
|
29713
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
362 |
|
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
363 |
if (find_positions(fd, bp, &base_offset, &censtart) == -1) { |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
364 |
return -1; |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
365 |
} |
eeabfe673c97
8073158: zip files with total entry count 0xFFFF need not be ZIP64 files
martin
parents:
29389
diff
changeset
|
366 |
if (JLI_Lseek(fd, censtart, SEEK_SET) < (jlong) 0) { |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
367 |
return -1; |
2 | 368 |
} |
369 |
||
370 |
if ((bytes = read(fd, bp, MINREAD)) < 0) { |
|
371 |
free(buffer); |
|
372 |
return (-1); |
|
373 |
} |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
374 |
p = bp; |
2 | 375 |
/* |
376 |
* Loop through the Central Directory Headers. Note that a valid zip/jar |
|
377 |
* must have an ENDHDR (with ENDSIG) after the Central Directory. |
|
378 |
*/ |
|
29389
348a32f79d79
8074579: Use more efficient and readable way of checking PKZIP signatures
martin
parents:
27938
diff
changeset
|
379 |
while (CENSIG_AT(p)) { |
2 | 380 |
|
381 |
/* |
|
382 |
* If a complete header isn't in the buffer, shift the contents |
|
383 |
* of the buffer down and refill the buffer. Note that the check |
|
384 |
* for "bytes < CENHDR" must be made before the test for the entire |
|
385 |
* size of the header, because if bytes is less than CENHDR, the |
|
386 |
* actual size of the header can't be determined. The addition of |
|
387 |
* SIGSIZ guarantees that the next signature is also in the buffer |
|
388 |
* for proper loop termination. |
|
389 |
*/ |
|
390 |
if (bytes < CENHDR) { |
|
391 |
p = memmove(bp, p, bytes); |
|
392 |
if ((res = read(fd, bp + bytes, MINREAD)) <= 0) { |
|
393 |
free(buffer); |
|
394 |
return (-1); |
|
395 |
} |
|
396 |
bytes += res; |
|
397 |
} |
|
398 |
entry_size = CENHDR + CENNAM(p) + CENEXT(p) + CENCOM(p); |
|
399 |
if (bytes < entry_size + SIGSIZ) { |
|
400 |
if (p != bp) |
|
401 |
p = memmove(bp, p, bytes); |
|
402 |
read_size = entry_size - bytes + SIGSIZ; |
|
403 |
read_size = (read_size < MINREAD) ? MINREAD : read_size; |
|
404 |
if ((res = read(fd, bp + bytes, read_size)) <= 0) { |
|
405 |
free(buffer); |
|
406 |
return (-1); |
|
407 |
} |
|
408 |
bytes += res; |
|
409 |
} |
|
410 |
||
411 |
/* |
|
412 |
* Check if the name is the droid we are looking for; the jar file |
|
413 |
* manifest. If so, build the entry record from the data found in |
|
414 |
* the header located and return success. |
|
415 |
*/ |
|
7028
adadd244f506
6989469: (launcher) compiler warnings in jli native code
ksrini
parents:
5506
diff
changeset
|
416 |
if ((size_t)CENNAM(p) == JLI_StrLen(file_name) && |
2 | 417 |
memcmp((p + CENHDR), file_name, JLI_StrLen(file_name)) == 0) { |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
418 |
if (JLI_Lseek(fd, base_offset + CENOFF(p), SEEK_SET) < (jlong)0) { |
2 | 419 |
free(buffer); |
420 |
return (-1); |
|
421 |
} |
|
422 |
if (read(fd, locbuf, LOCHDR) < 0) { |
|
423 |
free(buffer); |
|
424 |
return (-1); |
|
425 |
} |
|
29389
348a32f79d79
8074579: Use more efficient and readable way of checking PKZIP signatures
martin
parents:
27938
diff
changeset
|
426 |
if (!LOCSIG_AT(locbuf)) { |
2 | 427 |
free(buffer); |
428 |
return (-1); |
|
429 |
} |
|
430 |
entry->isize = CENLEN(p); |
|
431 |
entry->csize = CENSIZ(p); |
|
432 |
entry->offset = base_offset + CENOFF(p) + LOCHDR + |
|
433 |
LOCNAM(locbuf) + LOCEXT(locbuf); |
|
434 |
entry->how = CENHOW(p); |
|
435 |
free(buffer); |
|
436 |
return (0); |
|
437 |
} |
|
438 |
||
439 |
/* |
|
440 |
* Point to the next entry and decrement the count of valid remaining |
|
441 |
* bytes. |
|
442 |
*/ |
|
443 |
bytes -= entry_size; |
|
444 |
p += entry_size; |
|
445 |
} |
|
446 |
free(buffer); |
|
447 |
return (-1); /* Fell off the end the loop without a Manifest */ |
|
448 |
} |
|
449 |
||
450 |
/* |
|
451 |
* Parse a Manifest file header entry into a distinct "name" and "value". |
|
452 |
* Continuation lines are joined into a single "value". The documented |
|
453 |
* syntax for a header entry is: |
|
454 |
* |
|
455 |
* header: name ":" value |
|
456 |
* |
|
457 |
* name: alphanum *headerchar |
|
458 |
* |
|
459 |
* value: SPACE *otherchar newline *continuation |
|
460 |
* |
|
461 |
* continuation: SPACE *otherchar newline |
|
462 |
* |
|
463 |
* newline: CR LF | LF | CR (not followed by LF) |
|
464 |
* |
|
465 |
* alphanum: {"A"-"Z"} | {"a"-"z"} | {"0"-"9"} |
|
466 |
* |
|
467 |
* headerchar: alphanum | "-" | "_" |
|
468 |
* |
|
469 |
* otherchar: any UTF-8 character except NUL, CR and LF |
|
470 |
* |
|
471 |
* Note that a manifest file may be composed of multiple sections, |
|
472 |
* each of which may contain multiple headers. |
|
473 |
* |
|
474 |
* section: *header +newline |
|
475 |
* |
|
476 |
* nonempty-section: +header +newline |
|
477 |
* |
|
478 |
* (Note that the point of "nonempty-section" is unclear, because it isn't |
|
479 |
* referenced elsewhere in the full specification for the Manifest file.) |
|
480 |
* |
|
481 |
* Arguments: |
|
482 |
* lp pointer to a character pointer which points to the start |
|
483 |
* of a valid header. |
|
484 |
* name pointer to a character pointer which will be set to point |
|
485 |
* to the name portion of the header (nul terminated). |
|
486 |
* value pointer to a character pointer which will be set to point |
|
487 |
* to the value portion of the header (nul terminated). |
|
488 |
* |
|
489 |
* Returns: |
|
490 |
* 1 Successful parsing of an NV pair. lp is updated to point to the |
|
491 |
* next character after the terminating newline in the string |
|
492 |
* representing the Manifest file. name and value are updated to |
|
493 |
* point to the strings parsed. |
|
494 |
* 0 A valid end of section indicator was encountered. lp, name, and |
|
495 |
* value are not modified. |
|
496 |
* -1 lp does not point to a valid header. Upon return, the values of |
|
497 |
* lp, name, and value are undefined. |
|
498 |
*/ |
|
499 |
static int |
|
500 |
parse_nv_pair(char **lp, char **name, char **value) |
|
501 |
{ |
|
502 |
char *nl; |
|
503 |
char *cp; |
|
504 |
||
505 |
/* |
|
506 |
* End of the section - return 0. The end of section condition is |
|
507 |
* indicated by either encountering a blank line or the end of the |
|
508 |
* Manifest "string" (EOF). |
|
509 |
*/ |
|
510 |
if (**lp == '\0' || **lp == '\n' || **lp == '\r') |
|
511 |
return (0); |
|
512 |
||
513 |
/* |
|
514 |
* Getting to here, indicates that *lp points to an "otherchar". |
|
515 |
* Turn the "header" into a string on its own. |
|
516 |
*/ |
|
517 |
nl = JLI_StrPBrk(*lp, "\n\r"); |
|
518 |
if (nl == NULL) { |
|
519 |
nl = JLI_StrChr(*lp, (int)'\0'); |
|
520 |
} else { |
|
521 |
cp = nl; /* For merging continuation lines */ |
|
522 |
if (*nl == '\r' && *(nl+1) == '\n') |
|
523 |
*nl++ = '\0'; |
|
524 |
*nl++ = '\0'; |
|
525 |
||
526 |
/* |
|
527 |
* Process any "continuation" line(s), by making them part of the |
|
528 |
* "header" line. Yes, I know that we are "undoing" the NULs we |
|
529 |
* just placed here, but continuation lines are the fairly rare |
|
530 |
* case, so we shouldn't unnecessarily complicate the code above. |
|
531 |
* |
|
532 |
* Note that an entire continuation line is processed each iteration |
|
533 |
* through the outer while loop. |
|
534 |
*/ |
|
535 |
while (*nl == ' ') { |
|
536 |
nl++; /* First character to be moved */ |
|
537 |
while (*nl != '\n' && *nl != '\r' && *nl != '\0') |
|
538 |
*cp++ = *nl++; /* Shift string */ |
|
539 |
if (*nl == '\0') |
|
540 |
return (-1); /* Error: newline required */ |
|
541 |
*cp = '\0'; |
|
542 |
if (*nl == '\r' && *(nl+1) == '\n') |
|
543 |
*nl++ = '\0'; |
|
544 |
*nl++ = '\0'; |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
/* |
|
549 |
* Separate the name from the value; |
|
550 |
*/ |
|
551 |
cp = JLI_StrChr(*lp, (int)':'); |
|
552 |
if (cp == NULL) |
|
553 |
return (-1); |
|
554 |
*cp++ = '\0'; /* The colon terminates the name */ |
|
555 |
if (*cp != ' ') |
|
556 |
return (-1); |
|
557 |
*cp++ = '\0'; /* Eat the required space */ |
|
558 |
*name = *lp; |
|
559 |
*value = cp; |
|
560 |
*lp = nl; |
|
561 |
return (1); |
|
562 |
} |
|
563 |
||
564 |
/* |
|
565 |
* Read the manifest from the specified jar file and fill in the manifest_info |
|
566 |
* structure with the information found within. |
|
567 |
* |
|
568 |
* Error returns are as follows: |
|
569 |
* 0 Success |
|
570 |
* -1 Unable to open jarfile |
|
571 |
* -2 Error accessing the manifest from within the jarfile (most likely |
|
572 |
* a manifest is not present, or this isn't a valid zip/jar file). |
|
573 |
*/ |
|
574 |
int |
|
575 |
JLI_ParseManifest(char *jarfile, manifest_info *info) |
|
576 |
{ |
|
577 |
int fd; |
|
578 |
zentry entry; |
|
579 |
char *lp; |
|
580 |
char *name; |
|
581 |
char *value; |
|
582 |
int rc; |
|
583 |
char *splashscreen_name = NULL; |
|
584 |
||
585 |
if ((fd = open(jarfile, O_RDONLY |
|
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
586 |
#ifdef O_LARGEFILE |
15644
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
587 |
| O_LARGEFILE /* large file mode */ |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
7668
diff
changeset
|
588 |
#endif |
2 | 589 |
#ifdef O_BINARY |
590 |
| O_BINARY /* use binary mode on windows */ |
|
591 |
#endif |
|
16078 | 592 |
)) == -1) { |
2 | 593 |
return (-1); |
16078 | 594 |
} |
2 | 595 |
info->manifest_version = NULL; |
596 |
info->main_class = NULL; |
|
597 |
info->jre_version = NULL; |
|
598 |
info->jre_restrict_search = 0; |
|
599 |
info->splashscreen_image_file_name = NULL; |
|
29742
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
600 |
if ((rc = find_file(fd, &entry, manifest_name)) != 0) { |
2 | 601 |
close(fd); |
602 |
return (-2); |
|
603 |
} |
|
604 |
manifest = inflate_file(fd, &entry, NULL); |
|
605 |
if (manifest == NULL) { |
|
606 |
close(fd); |
|
607 |
return (-2); |
|
608 |
} |
|
609 |
lp = manifest; |
|
610 |
while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) { |
|
27938
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
611 |
if (JLI_StrCaseCmp(name, "Manifest-Version") == 0) { |
2 | 612 |
info->manifest_version = value; |
27938
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
613 |
} else if (JLI_StrCaseCmp(name, "Main-Class") == 0) { |
2 | 614 |
info->main_class = value; |
27938
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
615 |
} else if (JLI_StrCaseCmp(name, "JRE-Version") == 0) { |
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
616 |
/* |
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
617 |
* Manifest specification overridden by command line option |
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
618 |
* so we will silently override there with no specification. |
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
619 |
*/ |
7f7f8bf64dd7
8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents:
25859
diff
changeset
|
620 |
info->jre_version = 0; |
2 | 621 |
} else if (JLI_StrCaseCmp(name, "Splashscreen-Image") == 0) { |
622 |
info->splashscreen_image_file_name = value; |
|
623 |
} |
|
624 |
} |
|
625 |
close(fd); |
|
626 |
if (rc == 0) |
|
627 |
return (0); |
|
628 |
else |
|
629 |
return (-2); |
|
630 |
} |
|
631 |
||
632 |
/* |
|
633 |
* Opens the jar file and unpacks the specified file from its contents. |
|
634 |
* Returns NULL on failure. |
|
635 |
*/ |
|
636 |
void * |
|
637 |
JLI_JarUnpackFile(const char *jarfile, const char *filename, int *size) { |
|
638 |
int fd; |
|
639 |
zentry entry; |
|
640 |
void *data = NULL; |
|
641 |
||
16078 | 642 |
if ((fd = open(jarfile, O_RDONLY |
15644
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
643 |
#ifdef O_LARGEFILE |
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
644 |
| O_LARGEFILE /* large file mode */ |
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
645 |
#endif |
2 | 646 |
#ifdef O_BINARY |
647 |
| O_BINARY /* use binary mode on windows */ |
|
648 |
#endif |
|
16078 | 649 |
)) == -1) { |
650 |
return NULL; |
|
651 |
} |
|
652 |
if (find_file(fd, &entry, filename) == 0) { |
|
2 | 653 |
data = inflate_file(fd, &entry, size); |
654 |
} |
|
655 |
close(fd); |
|
656 |
return (data); |
|
657 |
} |
|
658 |
||
659 |
/* |
|
660 |
* Specialized "free" function. |
|
661 |
*/ |
|
662 |
void |
|
56230 | 663 |
JLI_FreeManifest(void) |
2 | 664 |
{ |
665 |
if (manifest) |
|
666 |
free(manifest); |
|
667 |
} |
|
668 |
||
669 |
/* |
|
670 |
* Iterate over the manifest of the specified jar file and invoke the provided |
|
671 |
* closure function for each attribute encountered. |
|
672 |
* |
|
673 |
* Error returns are as follows: |
|
674 |
* 0 Success |
|
675 |
* -1 Unable to open jarfile |
|
676 |
* -2 Error accessing the manifest from within the jarfile (most likely |
|
677 |
* this means a manifest is not present, or it isn't a valid zip/jar file). |
|
678 |
*/ |
|
679 |
int |
|
680 |
JLI_ManifestIterate(const char *jarfile, attribute_closure ac, void *user_data) |
|
681 |
{ |
|
682 |
int fd; |
|
683 |
zentry entry; |
|
684 |
char *mp; /* manifest pointer */ |
|
685 |
char *lp; /* pointer into manifest, updated during iteration */ |
|
686 |
char *name; |
|
687 |
char *value; |
|
688 |
int rc; |
|
689 |
||
690 |
if ((fd = open(jarfile, O_RDONLY |
|
15644
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
691 |
#ifdef O_LARGEFILE |
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
692 |
| O_LARGEFILE /* large file mode */ |
2dfa520c7303
8006995: java launcher fails to open executable JAR > 2GB
martin
parents:
13675
diff
changeset
|
693 |
#endif |
2 | 694 |
#ifdef O_BINARY |
695 |
| O_BINARY /* use binary mode on windows */ |
|
696 |
#endif |
|
16078 | 697 |
)) == -1) { |
2 | 698 |
return (-1); |
16078 | 699 |
} |
2 | 700 |
|
29742
b73f38796859
8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents:
29713
diff
changeset
|
701 |
if ((rc = find_file(fd, &entry, manifest_name)) != 0) { |
2 | 702 |
close(fd); |
703 |
return (-2); |
|
704 |
} |
|
705 |
||
706 |
mp = inflate_file(fd, &entry, NULL); |
|
707 |
if (mp == NULL) { |
|
708 |
close(fd); |
|
709 |
return (-2); |
|
710 |
} |
|
711 |
||
712 |
lp = mp; |
|
713 |
while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) { |
|
714 |
(*ac)(name, value, user_data); |
|
715 |
} |
|
716 |
free(mp); |
|
717 |
close(fd); |
|
7028
adadd244f506
6989469: (launcher) compiler warnings in jli native code
ksrini
parents:
5506
diff
changeset
|
718 |
return (rc == 0) ? 0 : -2; |
2 | 719 |
} |