[Lha-users] Re: file と ./file が別ファイル扱いされる

Back to archive index

Koji Arai jca02****@gmail*****
2007年 2月 21日 (水) 17:41:49 JST


新井です。

これでいかがでしょう?

07/02/21 に Koji Arai<jca02****@gmail*****> さんは書きました:
> 新井です。

> > > 「./././file」が救えませんから、もう少しスマートな方法にして
> > > あげないといけなさそうです...
> >
> > 安直に以下だとどうでしょうか?(あまり試してません)
>
> ごめんなさい。バグってます。安直過ぎました

diff -ru lha-1.14i-ac20061008/src/header.c lha/src/header.c
--- lha-1.14i-ac20061008/src/header.c	2006-10-08 23:20:14.000000000 +0900
+++ lha/src/header.c	2007-02-21 17:35:20.057974400 +0900
@@ -1214,6 +1214,55 @@
     return first;
 }

+int
+copy_one_path(char *dst, const char *src, int size)
+{
+    int i;
+
+    if (size < 1) return 0;
+
+    for (i = 0; i < size; i++) {
+        dst[i] = src[i];
+	if (dst[i] == '\0')
+	    return i;
+        if (dst[i] == '/') {
+            dst[++i] = 0;
+            return i;
+        }
+    }
+
+    dst[--i] = 0;
+
+    return i;
+}
+
+/* remove leading "xxx/../" and "./" */
+static int
+remove_dots(char *newpath, char *path, size_t size)
+{
+    int len;
+    char *p = newpath;
+
+    path = remove_leading_dots(path);
+
+    while (*path) {
+        if (path[0] == '.' && path[1] == '/')
+            path += 2;
+        else {
+            int len;
+            len = copy_one_path(newpath, path, size);
+
+            path += len;
+            newpath += len;
+            size -= len;
+            if (size <= 1)
+                break;
+        }
+    }
+
+    return newpath - p;
+}
+
 void
 init_header(name, v_stat, hdr)
     char           *name;
@@ -1232,9 +1281,9 @@
     hdr->original_size = v_stat->st_size;
     hdr->attribute = GENERIC_ATTRIBUTE;
     hdr->header_level = header_level;
-    len = str_safe_copy(hdr->name,
-                        remove_leading_dots(name),
-                        sizeof(hdr->name));
+
+    len = remove_dots(hdr->name, name, sizeof(hdr->name));
+
     hdr->crc = 0x0000;
     hdr->extend_type = EXTEND_UNIX;
     hdr->unix_last_modified_stamp = v_stat->st_mtime;

-- 
Koji Arai



Lha-users メーリングリストの案内
Back to archive index