Browse Source

Fix an issue with loader not handling implicit manifests

Don Porter 7 years ago
parent
commit
01d23117bd
1 changed files with 29 additions and 0 deletions
  1. 29 0
      Pal/src/db_main.c

+ 29 - 0
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");