|
|
f9c478 |
diff --git a/bins/unzip-mem.c b/bins/unzip-mem.c
|
|
|
f9c478 |
index c45cb72..ff564a5 100644
|
|
|
f9c478 |
--- a/bins/unzip-mem.c
|
|
|
f9c478 |
+++ b/bins/unzip-mem.c
|
|
|
f9c478 |
@@ -88,10 +88,53 @@ static void zzip_mem_entry_pipe(ZZIP_MEM_DISK* disk,
|
|
|
f9c478 |
}
|
|
|
f9c478 |
}
|
|
|
f9c478 |
|
|
|
f9c478 |
+
|
|
|
f9c478 |
+
|
|
|
f9c478 |
+
|
|
|
f9c478 |
+static inline void
|
|
|
f9c478 |
+remove_dotdotslash(char *path)
|
|
|
f9c478 |
+{
|
|
|
f9c478 |
+ /* Note: removing "../" from the path ALWAYS shortens the path, never adds to it! */
|
|
|
f9c478 |
+ char *dotdotslash;
|
|
|
f9c478 |
+ int warned = 0;
|
|
|
f9c478 |
+
|
|
|
f9c478 |
+ dotdotslash = path;
|
|
|
f9c478 |
+ while ((dotdotslash = strstr(dotdotslash, "../")) != NULL)
|
|
|
f9c478 |
+ {
|
|
|
f9c478 |
+ /*
|
|
|
f9c478 |
+ * Remove only if at the beginning of the pathname ("../path/name")
|
|
|
f9c478 |
+ * or when preceded by a slash ("path/../name"),
|
|
|
f9c478 |
+ * otherwise not ("path../name..")!
|
|
|
f9c478 |
+ */
|
|
|
f9c478 |
+ if (dotdotslash == path || dotdotslash[-1] == '/')
|
|
|
f9c478 |
+ {
|
|
|
f9c478 |
+ char *src, *dst;
|
|
|
f9c478 |
+ if (!warned)
|
|
|
f9c478 |
+ {
|
|
|
f9c478 |
+ /* Note: the first time through the pathname is still intact */
|
|
|
f9c478 |
+ fprintf(stderr, "Removing \"../\" path component(s) in %s\n", path);
|
|
|
f9c478 |
+ warned = 1;
|
|
|
f9c478 |
+ }
|
|
|
f9c478 |
+ /* We cannot use strcpy(), as there "The strings may not overlap" */
|
|
|
f9c478 |
+ for (src = dotdotslash+3, dst=dotdotslash; (*dst = *src) != '\0'; src++, dst++)
|
|
|
f9c478 |
+ ;
|
|
|
f9c478 |
+ }
|
|
|
f9c478 |
+ else
|
|
|
f9c478 |
+ dotdotslash +=3; /* skip this instance to prevent infinite loop */
|
|
|
f9c478 |
+ }
|
|
|
f9c478 |
+}
|
|
|
f9c478 |
+
|
|
|
f9c478 |
static void zzip_mem_entry_make(ZZIP_MEM_DISK* disk,
|
|
|
f9c478 |
ZZIP_MEM_ENTRY* entry)
|
|
|
f9c478 |
{
|
|
|
f9c478 |
- FILE* file = fopen (entry->zz_name, "w");
|
|
|
f9c478 |
+ char name_stripped[PATH_MAX+1];
|
|
|
f9c478 |
+ FILE* file;
|
|
|
f9c478 |
+
|
|
|
f9c478 |
+ strncpy(name_stripped, entry->zz_name, PATH_MAX);
|
|
|
f9c478 |
+ name_stripped[PATH_MAX]='\0';
|
|
|
f9c478 |
+ remove_dotdotslash(name_stripped);
|
|
|
f9c478 |
+
|
|
|
f9c478 |
+ file = fopen (name_stripped, "wb");
|
|
|
f9c478 |
if (file) { zzip_mem_entry_pipe (disk, entry, file); fclose (file); }
|
|
|
f9c478 |
perror (entry->zz_name);
|
|
|
f9c478 |
if (status < EXIT_WARNINGS) status = EXIT_WARNINGS;
|