[libc-commits] [libc] 816b5e5 - [libc] remove use after free in tests.

Michael Jones via libc-commits libc-commits at lists.llvm.org
Mon Dec 12 13:23:00 PST 2022


Author: Michael Jones
Date: 2022-12-12T13:22:56-08:00
New Revision: 816b5e546c6553afd463f9630b248a17702700c9

URL: https://github.com/llvm/llvm-project/commit/816b5e546c6553afd463f9630b248a17702700c9
DIFF: https://github.com/llvm/llvm-project/commit/816b5e546c6553afd463f9630b248a17702700c9.diff

LOG: [libc] remove use after free in tests.

There were some tests added that attempted to access files after they
were closed to test errno behavior, this caused sanitizer issues. Those
portions of the tests have been disabled.

Differential Revision: https://reviews.llvm.org/D139878

Added: 
    

Modified: 
    libc/test/src/stdio/fileop_test.cpp
    libc/test/src/stdio/ftell_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp
index 49af4683d7979..f473abd7278cd 100644
--- a/libc/test/src/stdio/fileop_test.cpp
+++ b/libc/test/src/stdio/fileop_test.cpp
@@ -114,18 +114,18 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
 
   // Check that the other functions correctly set errno.
 
-  errno = 0;
-  ASSERT_NE(__llvm_libc::fseek(file, 0, SEEK_SET), 0);
-  EXPECT_NE(errno, 0);
-
-  errno = 0;
-  ASSERT_NE(__llvm_libc::fclose(file), 0);
-  EXPECT_NE(errno, 0);
-
-  errno = 0;
-  ASSERT_EQ(__llvm_libc::fopen("INVALID FILE NAME", "r"),
-            static_cast<FILE *>(nullptr));
-  EXPECT_NE(errno, 0);
+  // errno = 0;
+  // ASSERT_NE(__llvm_libc::fseek(file, 0, SEEK_SET), 0);
+  // EXPECT_NE(errno, 0);
+
+  // errno = 0;
+  // ASSERT_NE(__llvm_libc::fclose(file), 0);
+  // EXPECT_NE(errno, 0);
+
+  // errno = 0;
+  // ASSERT_EQ(__llvm_libc::fopen("INVALID FILE NAME", "r"),
+  //           static_cast<FILE *>(nullptr));
+  // EXPECT_NE(errno, 0);
 }
 
 TEST(LlvmLibcFILETest, FFlush) {

diff  --git a/libc/test/src/stdio/ftell_test.cpp b/libc/test/src/stdio/ftell_test.cpp
index f83a74db10380..97facafe58bbb 100644
--- a/libc/test/src/stdio/ftell_test.cpp
+++ b/libc/test/src/stdio/ftell_test.cpp
@@ -55,9 +55,9 @@ class LlvmLibcFTellTest : public __llvm_libc::testing::Test {
 
     ASSERT_EQ(0, __llvm_libc::fclose(file));
 
-    errno = 0;
-    ASSERT_EQ(__llvm_libc::ftell(file), long(-1));
-    ASSERT_NE(errno, 0);
+    // errno = 0;
+    // ASSERT_EQ(__llvm_libc::ftell(file), long(-1));
+    // ASSERT_NE(errno, 0);
   }
 };
 


        


More information about the libc-commits mailing list