57 lines
1.8 KiB
Text
57 lines
1.8 KiB
Text
$NetBSD: patch-ad,v 1.6 2006/05/17 06:12:27 rillig Exp $
|
|
|
|
--- jartool.c.orig 2001-01-11 09:38:15.000000000 +0100
|
|
+++ jartool.c
|
|
@@ -171,4 +171,2 @@
|
|
|
|
-extern int errno;
|
|
-
|
|
void usage(char*);
|
|
@@ -1143,2 +1141,27 @@ int create_central_header(int fd){
|
|
|
|
+static void canonical_filename(char *filename)
|
|
+{
|
|
+ char *iterator, *iterator2;
|
|
+
|
|
+ for (;;) {
|
|
+ if (*filename == '/')
|
|
+ memmove(filename, filename + 1, strlen(filename));
|
|
+ else if (filename[0] == '.' && filename[1] == '/')
|
|
+ memmove(filename, filename + 2, strlen(filename) - 1);
|
|
+ else if (filename[0] == '.' && filename[1] == '.' && filename[2] == '/')
|
|
+ memmove(filename, filename + 3, strlen(filename) - 2);
|
|
+ else if ((iterator = strstr(filename, "//")) != NULL)
|
|
+ memmove(iterator, iterator + 1, strlen(iterator));
|
|
+ else if ((iterator = strstr(filename, "/./")) != NULL)
|
|
+ memmove(iterator, iterator + 2, strlen(iterator) - 1);
|
|
+ else if ((iterator = strstr(filename, "/../")) != NULL) {
|
|
+ for (iterator2 = iterator - 1; iterator2 > filename && *iterator2 != '/'; --iterator2)
|
|
+ continue;
|
|
+ /* iterator2 >= filename, handle the initial slash above, if necessary */
|
|
+ memmove(iterator2, iterator + 3, strlen(iterator) - 2);
|
|
+ } else
|
|
+ break;
|
|
+ }
|
|
+}
|
|
+
|
|
int extract_jar(int fd, char **files, int file_num){
|
|
@@ -1251,2 +1274,9 @@ int extract_jar(int fd, char **files, in
|
|
|
|
+ canonical_filename(filename);
|
|
+
|
|
+ if (*filename == '\0') {
|
|
+ fprintf(stderr, "Error extracting JAR archive, empty file name!\n");
|
|
+ exit(1);
|
|
+ }
|
|
+
|
|
#ifdef DEBUG
|
|
@@ -1563,2 +1593,9 @@ int list_jar(int fd, char **files, int f
|
|
filename[fnlen] = '\0';
|
|
+
|
|
+ canonical_filename(filename);
|
|
+ if (*filename == '\0') {
|
|
+ fprintf(stderr, "Error extracting JAR archive, empty file name!\n");
|
|
+ exit(1);
|
|
+ }
|
|
+
|
|
|