dpkg: fix handling of names with leading dots. Closes bug 783
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 8 Jan 2010 17:07:33 +0000 (18:07 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 8 Jan 2010 17:07:33 +0000 (18:07 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/dpkg.c

index 616bce977f07cac5bf44fc4555cc43b0e7a4a785..9f58b54e60e62c21378d3c80e23e809d501083cd 100644 (file)
@@ -1493,7 +1493,18 @@ static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
 {
        char *name_ptr = archive_handle->file_header->name;
 
-       name_ptr += strspn(name_ptr, "./");
+       /* Skip all leading "/" */
+       while (*name_ptr == '/')
+               name_ptr++;
+       /* Skip all leading "./" and "../" */
+       while (name_ptr[0] == '.') {
+               if (name_ptr[1] == '.' && name_ptr[2] == '/')
+                       name_ptr++;
+               if (name_ptr[1] != '/')
+                       break;
+               name_ptr += 2;
+       }
+
        if (name_ptr[0] != '\0') {
                archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
                data_extract_all(archive_handle);