Skip to content

Commit

Permalink
Fix paths when run from same directory as manifest
Browse files Browse the repository at this point in the history
Towards #37610

When the `script_uri` argument to the VM has no path separators the
value returned from `DirName` is identical to the input, and it is not
safe to use it as a prefix for concatenating relative paths.

- Compare the dirname against the script URI and use an empty prefix
  when they match, indicating we were unable to find a directory.
- Rename `absolute_filename` to `resolved_filename` since it is not
  absolute in all cases.

Change-Id: I62e5b06d240b55b3aa9d97d61c003adb812485e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110137
Reviewed-by: Alexander Aprelev <[email protected]>
Commit-Queue: Nate Bosch <[email protected]>
  • Loading branch information
natebosch authored and [email protected] committed Jul 24, 2019
1 parent 9d78664 commit 3999da0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions runtime/bin/dfe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ static bool TryReadKernelListBuffer(const char* script_uri,
uint8_t** kernel_ir,
intptr_t* kernel_ir_size) {
const char* kernel_list_dirname = DartUtils::DirName(script_uri);
if (strcmp(kernel_list_dirname, script_uri) == 0) {
kernel_list_dirname = "";
}
KernelIRNode* kernel_ir_head = nullptr;
KernelIRNode* kernel_ir_tail = nullptr;
// Add all kernels to the linked list
Expand All @@ -452,11 +455,11 @@ static bool TryReadKernelListBuffer(const char* script_uri,
intptr_t this_kernel_size;
uint8_t* this_buffer;

StringPointer absolute_filename(
StringPointer resolved_filename(
File::IsAbsolutePath(filename)
? strdup(filename)
: Utils::SCreate("%s%s", kernel_list_dirname, filename));
if (!TryReadFile(absolute_filename.c_str(), &this_buffer,
if (!TryReadFile(resolved_filename.c_str(), &this_buffer,
&this_kernel_size)) {
return false;
}
Expand Down

0 comments on commit 3999da0

Please sign in to comment.