Fix trailing slashes in manifests created by the kernel.

This commit is contained in:
Jonas 'Sortie' Termansen 2017-10-14 14:32:42 +02:00
parent 568c97c77f
commit 65a960dab0
1 changed files with 7 additions and 1 deletions

View File

@ -626,8 +626,14 @@ static void ExtractTix(Ref<Descriptor> 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);