From 01d23117bddfe08588c44ea78fa8e775df65b04d Mon Sep 17 00:00:00 2001 From: Don Porter Date: Fri, 3 Mar 2017 14:33:08 -0500 Subject: [PATCH] Fix an issue with loader not handling implicit manifests --- Pal/src/db_main.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Pal/src/db_main.c b/Pal/src/db_main.c index 98db3d51..f0b7b8ce 100644 --- a/Pal/src/db_main.c +++ b/Pal/src/db_main.c @@ -347,6 +347,35 @@ has_manifest: } } + /* If we still don't have an exec in the manifest, but we have a manifest + * try implicitly from the manifest name */ + if ((!exec_handle) && manifest_uri) { + size_t manifest_strlen = strlen(manifest_uri); + size_t exec_strlen = manifest_strlen - 9; + int success = 0; + // Try .manifest + if (strcmp_static(&manifest_uri[exec_strlen], ".manifest")) { + success = 1; + } else { + exec_strlen -= 4; + if (strcmp_static(&manifest_uri[exec_strlen], ".manifest.sgx")) { + success = 1; + } + } + + if (success) { + exec_uri = malloc(exec_strlen + 1); + if (!exec_uri) + init_fail(-PAL_ERROR_NOMEM, "Cannot allocate URI buf"); + memcpy (exec_uri, manifest_uri, exec_strlen); + exec_uri[exec_strlen] = '\0'; + ret = _DkStreamOpen(&exec_handle, exec_uri, PAL_ACCESS_RDONLY, + 0, 0, 0); + if (ret < 0) + init_fail(-ret, "cannot open executable"); + } + } + /* must be a ELF */ if (exec_handle && check_elf_object(exec_handle) < 0) init_fail(PAL_ERROR_INVAL, "executable is not a ELF binary");