]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Match full strings, not just prefixes.
authorJoerg Sonnenberger <joerg@bec.de>
Tue, 5 Sep 2017 16:15:45 +0000 (18:15 +0200)
committerJoerg Sonnenberger <joerg@bec.de>
Tue, 5 Sep 2017 16:15:45 +0000 (18:15 +0200)
libarchive/archive_read_support_format_xar.c

index 93eeacc5e6ebc99b8d9d23f64f9ac41f5713fd52..602fc77221444ace07bbc77e2cc517dea0afd9e3 100644 (file)
@@ -2629,6 +2629,14 @@ strappend_base64(struct xar *xar,
                archive_strncat(as, (const char *)buff, len);
 }
 
+static int
+is_string(const char *known, const char *data, size_t len)
+{
+       if (strlen(known) != len)
+               return -1;
+       return memcmp(data, known, len);
+}
+
 static void
 xml_data(void *userData, const char *s, int len)
 {
@@ -2680,26 +2688,26 @@ xml_data(void *userData, const char *s, int len)
                archive_strncpy(&(xar->file->symlink), s, len);
                break;
        case FILE_TYPE:
-               if (strncmp("file", s, len) == 0 ||
-                   strncmp("hardlink", s, len) == 0)
+               if (is_string("file", s, len) == 0 ||
+                   is_string("hardlink", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFREG;
-               if (strncmp("directory", s, len) == 0)
+               if (is_string("directory", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFDIR;
-               if (strncmp("symlink", s, len) == 0)
+               if (is_string("symlink", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFLNK;
-               if (strncmp("character special", s, len) == 0)
+               if (is_string("character special", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFCHR;
-               if (strncmp("block special", s, len) == 0)
+               if (is_string("block special", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFBLK;
-               if (strncmp("socket", s, len) == 0)
+               if (is_string("socket", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFSOCK;
-               if (strncmp("fifo", s, len) == 0)
+               if (is_string("fifo", s, len) == 0)
                        xar->file->mode =
                            (xar->file->mode & ~AE_IFMT) | AE_IFIFO;
                xar->file->has |= HAS_TYPE;