From 65a960dab0684784ce72206020ba44a3b237e1cd Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 14 Oct 2017 14:32:42 +0200 Subject: [PATCH] Fix trailing slashes in manifests created by the kernel. --- kernel/initrd.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/initrd.cpp b/kernel/initrd.cpp index ee0b82d8..0528499c 100644 --- a/kernel/initrd.cpp +++ b/kernel/initrd.cpp @@ -626,8 +626,14 @@ static void ExtractTix(Ref desc, struct initrd_context* ctx) { if ( strncmp(TAR.name, "data", 4) != 0 || TAR.name[4] != '/' ) continue; - if ( !(manifest_list[manifest_list_count++] = strdup(TAR.name + 4)) ) + char* path = strdup(TAR.name + 4); + if ( !path ) Panic("initrd tar malloc failure"); + size_t length = strlen(path); + // Trim the trailing slash from directories. + if ( 2 <= length && path[length-1] == '/' ) + path[length-1] = '\0'; + manifest_list[manifest_list_count++] = path; } CloseTar(&TAR); qsort(manifest_list, manifest_list_count, sizeof(char*), manifest_sort);