Skip to content

[clang][test] Avoid writing to a potentially write-protected dir #96457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

karka228
Copy link
Collaborator

@karka228 karka228 commented Jun 24, 2024

The test clang/test/Preprocessor/embed_weird.cpp creates a file directly in the Inputs dir in the llvm-project repo instead of the temporary directory. The llvm-project repo may be write protected e.g. in a sandboxed environment.

This patch creates a separate temporary directory where the null_byte.bin file is created along with the rest of copies of the other embed-files needed for the testcase.

The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the
Inputs dir in the llvm-project repo instead of the temporary directory. The
llvm-project repo may be write protected e.g. in a sandboxed environment.

This patch create a separate temporary directory where the the null_byte.bin
file is created along with the rest of copies of the other embed-files needed
for the testcase.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2024

@llvm/pr-subscribers-clang

Author: Karl-Johan Karlsson (karka228)

Changes

The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the Inputs dir in the llvm-project repo instead of the temporary directory. The llvm-project repo may be write protected e.g. in a sandboxed environment.

This patch create a separate temporary directory where the the null_byte.bin file is created along with the rest of copies of the other embed-files needed for the testcase.


Full diff: https://github.com/llvm/llvm-project/pull/96457.diff

1 Files Affected:

  • (modified) clang/test/Preprocessor/embed_weird.cpp (+6-4)
diff --git a/clang/test/Preprocessor/embed_weird.cpp b/clang/test/Preprocessor/embed_weird.cpp
index a90d3bc330538..31b622c848d6a 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -1,7 +1,9 @@
-// RUN: printf "\0" > %S/Inputs/null_byte.bin
-// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,cxx -Wno-c23-extensions
-// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,c
-// RUN: rm %S/Inputs/null_byte.bin
+// RUN: rm -rf %t && mkdir -p %t/media
+// RUN: cp %S/Inputs/single_byte.txt %S/Inputs/jk.txt %S/Inputs/numbers.txt %t/
+// RUN: cp %S/Inputs/media/empty %t/media/
+// RUN: printf "\0" > %t/null_byte.bin
+// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%t -verify=expected,cxx -Wno-c23-extensions
+// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%t -verify=expected,c
 #embed <media/empty>
 ;
 

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry about that mistake in the test. The patch is LGTM. Thanks!

@karka228 karka228 merged commit 7e77353 into llvm:main Jun 25, 2024
9 checks passed
@karka228
Copy link
Collaborator Author

Whoops, sorry about that mistake in the test. The patch is LGTM. Thanks!

Thanks for the fast review :-)

AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…m#96457)

The test clang/test/Preprocessor/embed_weird.cpp creates a file directly
in the Inputs dir in the llvm-project repo instead of the temporary
directory. The llvm-project repo may be write protected e.g. in a
sandboxed environment.

This patch creates a separate temporary directory where the
null_byte.bin file is created along with the rest of copies of the other
embed-files needed for the testcase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants