Skip to content
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

[flang][unittests] Fix buffer overrun in FrontendActionTest #84381

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Mar 7, 2024

When SmallVector<char> is used as a backing storage, it can't be assumed to end with a \x0. When creating a StringRef from it, pass the length explicitly.

This was detected by address sanitizer.

When SmallVector<char> is used as a backing storage, it can't be
assumed to end with a \x0. When creating a StringRef from it, pass
the length explicitly.

This was detected by address sanitizer.
@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category labels Mar 7, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 7, 2024

@llvm/pr-subscribers-flang-driver

Author: Krzysztof Parzyszek (kparzysz)

Changes

When SmallVector&lt;char&gt; is used as a backing storage, it can't be assumed to end with a \x0. When creating a StringRef from it, pass the length explicitly.

This was detected by address sanitizer.


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

1 Files Affected:

  • (modified) flang/unittests/Frontend/FrontendActionTest.cpp (+3-2)
diff --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp
index 6ec15832d96d3c..123f428cc8b40b 100644
--- a/flang/unittests/Frontend/FrontendActionTest.cpp
+++ b/flang/unittests/Frontend/FrontendActionTest.cpp
@@ -198,7 +198,7 @@ TEST_F(FrontendActionTest, EmitLLVM) {
   EXPECT_TRUE(success);
   EXPECT_TRUE(!outputFileBuffer.empty());
 
-  EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data())
+  EXPECT_TRUE(llvm::StringRef(outputFileBuffer.begin(), outputFileBuffer.size())
                   .contains("define void @_QQmain()"));
 }
 
@@ -227,6 +227,7 @@ TEST_F(FrontendActionTest, EmitAsm) {
   EXPECT_TRUE(success);
   EXPECT_TRUE(!outputFileBuffer.empty());
 
-  EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data()).contains("_QQmain"));
+  EXPECT_TRUE(llvm::StringRef(outputFileBuffer.begin(), outputFileBuffer.size())
+                  .contains("_QQmain"));
 }
 } // namespace

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kparzysz kparzysz merged commit aa26faf into llvm:main Mar 8, 2024
7 checks passed
@kparzysz kparzysz deleted the users/kparzysz/asan-02 branch March 8, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants