Skip to content

Commit 651e3ff

Browse files
committed
[llvm-cov] Do not allow ".." to escape the coverage sub-directory
In -output-dir mode, file reports are placed into a "coverage" directory. If filenames in the coverage mapping contain "..", they might escape out of this directory. Fix the problem by removing ".." from source filenames (expand the path component). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274135 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 108515e commit 651e3ff

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed
116 Bytes
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
main
2+
# Func Hash:
3+
0
4+
# Num Counters:
5+
1
6+
# Counter Values:
7+
1
8+

test/tools/llvm-cov/double_dots.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// To create the covmapping for this file, copy this file to /tmp/dots/test.c,
2+
// cd into /tmp/dots, and pass "../dots/double_dots.c" to the compiler. Use
3+
// llvm-cov convert-for-testing to extract the covmapping.
4+
5+
// RUN: llvm-profdata merge %S/Inputs/double_dots.proftext -o %t.profdata
6+
// RUN: llvm-cov show %S/Inputs/double_dots.covmapping -instr-profile=%t.profdata -o %t.dir
7+
// RUN: FileCheck -input-file=%t.dir/index.txt %s
8+
9+
// CHECK-NOT: coverage{{.*}}dots{{.*}}..{{.*}}dots
10+
11+
int main() {}

tools/llvm-cov/SourceCoverageView.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension,
3535
if (!InToplevel)
3636
sys::path::append(FullPath, getCoverageDir());
3737

38-
auto PathBaseDir = sys::path::relative_path(sys::path::parent_path(Path));
39-
sys::path::append(FullPath, PathBaseDir);
38+
SmallString<256> ParentPath = sys::path::parent_path(Path);
39+
sys::path::remove_dots(ParentPath, /*remove_dot_dots=*/true);
40+
sys::path::append(FullPath, sys::path::relative_path(ParentPath));
4041

4142
auto PathFilename = (sys::path::filename(Path) + "." + Extension).str();
4243
sys::path::append(FullPath, PathFilename);

0 commit comments

Comments
 (0)