OSDN Git Service

* src/lhadd.c (remove_leading_dots): newly added.
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sat, 7 May 2005 20:31:33 +0000 (20:31 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sat, 7 May 2005 20:31:33 +0000 (20:31 +0000)
* src/lhadd.c (append_it): remove leading relative path from
archive.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@817 6a8cc165-1e22-0410-a132-eb4e3f353aba

src/lhadd.c

index 4ce0dca..e662e94 100644 (file)
@@ -73,8 +73,42 @@ add_one(fp, nafp, hdr)
     fseeko(nafp, next_pos, SEEK_SET);
 }
 
+static char *
+remove_leading_dots(char *path)
+{
+    char *first = path;
+    char *ptr = 0;
+
+    if (strcmp(first, "..") == 0) {
+        first[1] = 0;
+        return first;
+    }
+
+    if (strstr(first, "..") == 0)
+        return first;
+
+    while (path && *path) {
+
+        if (strcmp(path, "..") == 0)
+            ptr = path = path+2;
+        else if (strncmp(path, "../", 3) == 0)
+            ptr = path = path+3;
+        else
+            path = strchr(path, '/');
+
+        if (path && *path == '/') {
+            path++;
+        }
+    }
+
+    if (ptr) {
+        warning("Removing leading `%.*s' from member name.", ptr-first, first);
+        return ptr;
+    }
+
+    return first;
+}
 
-/* ------------------------------------------------------------------------ */
 FILE           *
 append_it(name, oafp, nafp)
     char           *name;
@@ -102,7 +136,6 @@ append_it(name, oafp, nafp)
 #else
     symlink = 0;
 #endif
-    init_header(name, &stbuf, &hdr);
 
     fp = NULL;
     if (!directory && !symlink && !noexec) {
@@ -113,6 +146,8 @@ append_it(name, oafp, nafp)
         }
     }
 
+    init_header(remove_leading_dots(name), &stbuf, &hdr);
+
     cmp = 0;                    /* avoid compiler warnings `uninitialized' */
     while (oafp) {
         old_header = ftello(oafp);