Skip to content

[libc] Fix readlink tests on 32-bit systems #97850

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
Jul 5, 2024

Conversation

mikhailramalho
Copy link
Member

Use sizeof in a string literal instead of a CString so we get the right size when creating the buf array.

We also now use strlen(FILENAME) to get the string lenght when calling readlink and readlinkat.

@llvmbot
Copy link
Member

llvmbot commented Jul 5, 2024

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

Use sizeof in a string literal instead of a CString so we get the right size when creating the buf array.

We also now use strlen(FILENAME) to get the string lenght when calling readlink and readlinkat.


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

3 Files Affected:

  • (modified) libc/test/src/unistd/CMakeLists.txt (+2)
  • (modified) libc/test/src/unistd/readlink_test.cpp (+7-4)
  • (modified) libc/test/src/unistd/readlinkat_test.cpp (+9-6)
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index de3e8d9ccbb626..b311bbf59bbca2 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -262,6 +262,7 @@ add_libc_unittest(
     libc.include.unistd
     libc.src.errno.errno
     libc.src.unistd.readlink
+    libc.src.string.strlen
     libc.src.unistd.symlink
     libc.src.unistd.unlink
     libc.src.__support.CPP.string_view
@@ -279,6 +280,7 @@ add_libc_unittest(
     libc.include.unistd
     libc.src.errno.errno
     libc.src.unistd.readlinkat
+    libc.src.string.strlen
     libc.src.unistd.symlink
     libc.src.unistd.unlink
     libc.src.__support.CPP.string_view
diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp
index 20f3951349118a..cd2a36ed86b11d 100644
--- a/libc/test/src/unistd/readlink_test.cpp
+++ b/libc/test/src/unistd/readlink_test.cpp
@@ -8,6 +8,7 @@
 
 #include "src/__support/CPP/string_view.h"
 #include "src/errno/libc_errno.h"
+#include "src/string/strlen.h"
 #include "src/unistd/readlink.h"
 #include "src/unistd/symlink.h"
 #include "src/unistd/unlink.h"
@@ -30,8 +31,9 @@ TEST(LlvmLibcReadlinkTest, CreateAndUnlink) {
   //   3. Cleanup the symlink created in step #1.
   ASSERT_THAT(LIBC_NAMESPACE::symlink(LINK_VAL, LINK), Succeeds(0));
 
-  char buf[sizeof(LINK_VAL)];
-  ssize_t len = LIBC_NAMESPACE::readlink(LINK, buf, sizeof(buf));
+  char buf[sizeof(FILENAME)];
+  ssize_t len =
+      LIBC_NAMESPACE::readlink(LINK, buf, LIBC_NAMESPACE::strlen(FILENAME));
   ASSERT_ERRNO_SUCCESS();
   ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL));
 
@@ -40,7 +42,8 @@ TEST(LlvmLibcReadlinkTest, CreateAndUnlink) {
 
 TEST(LlvmLibcReadlinkTest, ReadlinkInNonExistentPath) {
   using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
-  char buf[8];
-  ASSERT_THAT(LIBC_NAMESPACE::readlink("non-existent-link", buf, sizeof(buf)),
+  constexpr auto len = 8;
+  char buf[len];
+  ASSERT_THAT(LIBC_NAMESPACE::readlink("non-existent-link", buf, len),
               Fails(ENOENT));
 }
diff --git a/libc/test/src/unistd/readlinkat_test.cpp b/libc/test/src/unistd/readlinkat_test.cpp
index 39d81d9ba544a6..33c6c8968b1438 100644
--- a/libc/test/src/unistd/readlinkat_test.cpp
+++ b/libc/test/src/unistd/readlinkat_test.cpp
@@ -8,6 +8,7 @@
 
 #include "src/__support/CPP/string_view.h"
 #include "src/errno/libc_errno.h"
+#include "src/string/strlen.h"
 #include "src/unistd/readlinkat.h"
 #include "src/unistd/symlink.h"
 #include "src/unistd/unlink.h"
@@ -32,8 +33,9 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) {
   //   3. Cleanup the symlink created in step #1.
   ASSERT_THAT(LIBC_NAMESPACE::symlink(LINK_VAL, LINK), Succeeds(0));
 
-  char buf[sizeof(LINK_VAL)];
-  ssize_t len = LIBC_NAMESPACE::readlinkat(AT_FDCWD, LINK, buf, sizeof(buf));
+  char buf[sizeof(FILENAME)];
+  ssize_t len = LIBC_NAMESPACE::readlinkat(AT_FDCWD, LINK, buf,
+                                           LIBC_NAMESPACE::strlen(FILENAME));
   ASSERT_ERRNO_SUCCESS();
   ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL));
 
@@ -42,8 +44,9 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) {
 
 TEST(LlvmLibcReadlinkatTest, ReadlinkInNonExistentPath) {
   using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
-  char buf[8];
-  ASSERT_THAT(LIBC_NAMESPACE::readlinkat(AT_FDCWD, "non-existent-link", buf,
-                                         sizeof(buf)),
-              Fails(ENOENT));
+  constexpr auto len = 8;
+  char buf[len];
+  ASSERT_THAT(
+      LIBC_NAMESPACE::readlinkat(AT_FDCWD, "non-existent-link", buf, len),
+      Fails(ENOENT));
 }

Use sizeof in a string literal instead of a CString so we get the right
size when creating the buf array.

We also now use strlen(FILENAME) to get the string lenght when calling
readlink and readlinkat.
@mikhailramalho mikhailramalho merged commit 0f1da49 into llvm:main Jul 5, 2024
3 of 5 checks passed
@mikhailramalho mikhailramalho deleted the fix-readlink branch July 5, 2024 18:20
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 5, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian running on libc-x86_64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/43/builds/1493

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[ RUN      ] LlvmLibcRoundToIntegerTest.RoundNumbers
[       OK ] LlvmLibcRoundToIntegerTest.RoundNumbers (15 us)
[ RUN      ] LlvmLibcRoundToIntegerTest.SubnormalRange
[       OK ] LlvmLibcRoundToIntegerTest.SubnormalRange (868 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[625/630] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[626/630] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[627/630] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[628/630] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[629/630] Running unit test libc.test.src.unistd.readlinkat_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkatTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/test/src/unistd/readlinkat_test.cpp:42: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
[630/630] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/test/src/unistd/readlink_test.cpp:40: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 132, in main
    run_command(['ninja', 'libc-unit-tests'])
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja', 'libc-unit-tests']' returned non-zero exit status 1.
@@@STEP_FAILURE@@@
@@@BUILD_STEP libc-fuzzer@@@
Running: ninja libc-fuzzer
ninja: no work to do.
Step 7 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[ RUN      ] LlvmLibcRoundToIntegerTest.RoundNumbers
[       OK ] LlvmLibcRoundToIntegerTest.RoundNumbers (15 us)
[ RUN      ] LlvmLibcRoundToIntegerTest.SubnormalRange
[       OK ] LlvmLibcRoundToIntegerTest.SubnormalRange (868 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[625/630] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[626/630] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[627/630] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[628/630] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[629/630] Running unit test libc.test.src.unistd.readlinkat_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkatTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/test/src/unistd/readlinkat_test.cpp:42: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
[630/630] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/test/src/unistd/readlink_test.cpp:40: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 132, in main
    run_command(['ninja', 'libc-unit-tests'])
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja', 'libc-unit-tests']' returned non-zero exit status 1.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 5, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-fullbuild-dbg-asan running on libc-x86_64-debian-fullbuild while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/1485

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[688/695] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[689/695] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[690/695] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (45 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[691/695] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[692/695] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[693/695] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
=================================================================
==2592106==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdbee5b728 at pc 0x555f9be40d55 bp 0x7ffdbee5b410 sp 0x7ffdbee5b408
READ of size 1 at 0x7ffdbee5b728 thread T0
    #0 0x555f9be40d54 in __llvm_libc_19_0_0_git::cpp::string_view::compareMemory(char const*, char const*, unsigned long) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:34:27
    #1 0x555f9be40d54 in __llvm_libc_19_0_0_git::cpp::string_view::equals(__llvm_libc_19_0_0_git::cpp::string_view) const /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:47:13
    #2 0x555f9be40d54 in __llvm_libc_19_0_0_git::cpp::string_view::operator==(__llvm_libc_19_0_0_git::cpp::string_view) const /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:111:65
    #3 0x555f9be40d54 in bool __llvm_libc_19_0_0_git::testing::internal::test<__llvm_libc_19_0_0_git::cpp::string_view>(__llvm_libc_19_0_0_git::testing::internal::RunContext*, __llvm_libc_19_0_0_git::testing::TestCond, __llvm_libc_19_0_0_git::cpp::string_view, __llvm_libc_19_0_0_git::cpp::string_view, char const*, char const*, __llvm_libc_19_0_0_git::testing::internal::Location) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:93:34
    #4 0x555f9be29dd8 in bool __llvm_libc_19_0_0_git::testing::Test::test<__llvm_libc_19_0_0_git::cpp::string_view, 0>(__llvm_libc_19_0_0_git::testing::TestCond, __llvm_libc_19_0_0_git::cpp::string_view, __llvm_libc_19_0_0_git::cpp::string_view, char const*, char const*, __llvm_libc_19_0_0_git::testing::internal::Location) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.h:170:12
    #5 0x555f9be29dd8 in LlvmLibcReadlinkTest_CreateAndUnlink::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/unistd/readlink_test.cpp:38:3
    #6 0x555f9be2f610 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:165:8
    #7 0x555f9be493f1 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #8 0x7f1c05767249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)

Address 0x7ffdbee5b728 is located in stack of thread T0 at offset 360 in frame
    #0 0x555f9be296cf in LlvmLibcReadlinkTest_CreateAndUnlink::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/unistd/readlink_test.cpp:20

  This frame has 9 object(s):
    [32, 48) 'agg.tmp3272'
    [64, 80) 'agg.tmp2262'
    [96, 112) 'agg.tmp1154'
    [128, 144) 'agg.tmp50'
    [160, 184) 'LINK_VAL' (line 23)
    [224, 248) 'LINK' (line 25)
    [288, 320) 'ref.tmp' (line 32)
    [352, 360) 'buf' (line 34) <== Memory access at offset 360 overflows this variable
    [384, 416) 'ref.tmp29' (line 40)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:34:27 in __llvm_libc_19_0_0_git::cpp::string_view::compareMemory(char const*, char const*, unsigned long)
Shadow bytes around the buggy address:
  0x100037dc3690: 00 00 00 00 00 00 00 00 00 f3 f3 f3 f3 f3 f3 f3
  0x100037dc36a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100037dc36b0: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8 f2 f2
  0x100037dc36c0: 00 00 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 00 00 00 f2
  0x100037dc36d0: f2 f2 f2 f2 00 00 00 f2 f2 f2 f2 f2 f8 f8 f8 f8
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[688/695] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[689/695] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[690/695] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (45 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[691/695] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[692/695] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[693/695] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
=================================================================
==2592106==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdbee5b728 at pc 0x555f9be40d55 bp 0x7ffdbee5b410 sp 0x7ffdbee5b408
READ of size 1 at 0x7ffdbee5b728 thread T0
    #0 0x555f9be40d54 in __llvm_libc_19_0_0_git::cpp::string_view::compareMemory(char const*, char const*, unsigned long) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:34:27
    #1 0x555f9be40d54 in __llvm_libc_19_0_0_git::cpp::string_view::equals(__llvm_libc_19_0_0_git::cpp::string_view) const /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:47:13
    #2 0x555f9be40d54 in __llvm_libc_19_0_0_git::cpp::string_view::operator==(__llvm_libc_19_0_0_git::cpp::string_view) const /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:111:65
    #3 0x555f9be40d54 in bool __llvm_libc_19_0_0_git::testing::internal::test<__llvm_libc_19_0_0_git::cpp::string_view>(__llvm_libc_19_0_0_git::testing::internal::RunContext*, __llvm_libc_19_0_0_git::testing::TestCond, __llvm_libc_19_0_0_git::cpp::string_view, __llvm_libc_19_0_0_git::cpp::string_view, char const*, char const*, __llvm_libc_19_0_0_git::testing::internal::Location) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:93:34
    #4 0x555f9be29dd8 in bool __llvm_libc_19_0_0_git::testing::Test::test<__llvm_libc_19_0_0_git::cpp::string_view, 0>(__llvm_libc_19_0_0_git::testing::TestCond, __llvm_libc_19_0_0_git::cpp::string_view, __llvm_libc_19_0_0_git::cpp::string_view, char const*, char const*, __llvm_libc_19_0_0_git::testing::internal::Location) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.h:170:12
    #5 0x555f9be29dd8 in LlvmLibcReadlinkTest_CreateAndUnlink::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/unistd/readlink_test.cpp:38:3
    #6 0x555f9be2f610 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:165:8
    #7 0x555f9be493f1 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #8 0x7f1c05767249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)

Address 0x7ffdbee5b728 is located in stack of thread T0 at offset 360 in frame
    #0 0x555f9be296cf in LlvmLibcReadlinkTest_CreateAndUnlink::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/unistd/readlink_test.cpp:20

  This frame has 9 object(s):
    [32, 48) 'agg.tmp3272'
    [64, 80) 'agg.tmp2262'
    [96, 112) 'agg.tmp1154'
    [128, 144) 'agg.tmp50'
    [160, 184) 'LINK_VAL' (line 23)
    [224, 248) 'LINK' (line 25)
    [288, 320) 'ref.tmp' (line 32)
    [352, 360) 'buf' (line 34) <== Memory access at offset 360 overflows this variable
    [384, 416) 'ref.tmp29' (line 40)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:34:27 in __llvm_libc_19_0_0_git::cpp::string_view::compareMemory(char const*, char const*, unsigned long)
Shadow bytes around the buggy address:
  0x100037dc3690: 00 00 00 00 00 00 00 00 00 f3 f3 f3 f3 f3 f3 f3
  0x100037dc36a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100037dc36b0: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8 f2 f2
  0x100037dc36c0: 00 00 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 00 00 00 f2
  0x100037dc36d0: f2 f2 f2 f2 00 00 00 f2 f2 f2 f2 f2 f8 f8 f8 f8

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 5, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-gcc-fullbuild-dbg running on libc-x86_64-debian-fullbuild while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/131/builds/1494

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[692/699] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[693/699] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[694/699] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (34 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[695/699] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[696/699] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[697/699] Running unit test libc.test.src.unistd.readlinkat_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkatTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/src/unistd/readlinkat_test.cpp:42: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
[698/699] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/src/unistd/readlink_test.cpp:40: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
[699/699] Running unit test libc.test.src.__support.hash_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcHashTest.SanityCheck
[       OK ] LlvmLibcHashTest.SanityCheck (9 ms)
[ RUN      ] LlvmLibcHashTest.Avalanche
[       OK ] LlvmLibcHashTest.Avalanche (4887 ms)
[ RUN      ] LlvmLibcHashTest.UniformLSB
[       OK ] LlvmLibcHashTest.UniformLSB (461 ms)
[ RUN      ] LlvmLibcHashTest.UniformMSB
[       OK ] LlvmLibcHashTest.UniformMSB (2 ms)
Ran 4 tests.  PASS: 4  FAIL: 0
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 132, in main
    run_command(['ninja', 'libc-unit-tests'])
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[692/699] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[693/699] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[694/699] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (34 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[695/699] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[696/699] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[697/699] Running unit test libc.test.src.unistd.readlinkat_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkatTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/src/unistd/readlinkat_test.cpp:42: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
[698/699] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/src/unistd/readlink_test.cpp:40: FAILURE
Failed to match LIBC_NAMESPACE::unlink(LINK) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "Bad address".
Segmentation fault
[699/699] Running unit test libc.test.src.__support.hash_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcHashTest.SanityCheck
[       OK ] LlvmLibcHashTest.SanityCheck (9 ms)
[ RUN      ] LlvmLibcHashTest.Avalanche
[       OK ] LlvmLibcHashTest.Avalanche (4887 ms)
[ RUN      ] LlvmLibcHashTest.UniformLSB
[       OK ] LlvmLibcHashTest.UniformLSB (461 ms)
[ RUN      ] LlvmLibcHashTest.UniformMSB
[       OK ] LlvmLibcHashTest.UniformMSB (2 ms)
Ran 4 tests.  PASS: 4  FAIL: 0
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 132, in main
    run_command(['ninja', 'libc-unit-tests'])
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 5, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-dbg-asan running on libc-x86_64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/147/builds/1446

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[ RUN      ] LlvmLibcRoundToIntegerTest.RoundNumbers
[       OK ] LlvmLibcRoundToIntegerTest.RoundNumbers (21 us)
[ RUN      ] LlvmLibcRoundToIntegerTest.SubnormalRange
[       OK ] LlvmLibcRoundToIntegerTest.SubnormalRange (1129 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[622/627] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlinkat_test.__build__.dir/readlinkat_test.cpp.o
[623/627] Building CXX object projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test.__build__.dir/readlink_test.cpp.o
[624/627] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlinkat_test.__build__
[625/627] Linking CXX executable projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[626/627] Running unit test libc.test.src.unistd.readlink_test
FAILED: projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/unistd/CMakeFiles/libc.test.src.unistd.readlink_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/unistd && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcReadlinkTest.CreateAndUnlink
=================================================================
==2383243==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd8b2ca728 at pc 0x55d62cef3bc5 bp 0x7ffd8b2ca410 sp 0x7ffd8b2ca408
READ of size 1 at 0x7ffd8b2ca728 thread T0
    #0 0x55d62cef3bc4 in __llvm_libc_19_0_0_git::cpp::string_view::compareMemory(char const*, char const*, unsigned long) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:34:27
    #1 0x55d62cef3bc4 in __llvm_libc_19_0_0_git::cpp::string_view::equals(__llvm_libc_19_0_0_git::cpp::string_view) const /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:47:13
    #2 0x55d62cef3bc4 in __llvm_libc_19_0_0_git::cpp::string_view::operator==(__llvm_libc_19_0_0_git::cpp::string_view) const /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:111:65
    #3 0x55d62cef3bc4 in bool __llvm_libc_19_0_0_git::testing::internal::test<__llvm_libc_19_0_0_git::cpp::string_view>(__llvm_libc_19_0_0_git::testing::internal::RunContext*, __llvm_libc_19_0_0_git::testing::TestCond, __llvm_libc_19_0_0_git::cpp::string_view, __llvm_libc_19_0_0_git::cpp::string_view, char const*, char const*, __llvm_libc_19_0_0_git::testing::internal::Location) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:93:34
    #4 0x55d62cedcccc in bool __llvm_libc_19_0_0_git::testing::Test::test<__llvm_libc_19_0_0_git::cpp::string_view, 0>(__llvm_libc_19_0_0_git::testing::TestCond, __llvm_libc_19_0_0_git::cpp::string_view, __llvm_libc_19_0_0_git::cpp::string_view, char const*, char const*, __llvm_libc_19_0_0_git::testing::internal::Location) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.h:170:12
    #5 0x55d62cedcccc in LlvmLibcReadlinkTest_CreateAndUnlink::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/unistd/readlink_test.cpp:38:3
    #6 0x55d62cee2480 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:165:8
    #7 0x55d62cefc261 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #8 0x7f962e846249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)
    #9 0x7f962e846304 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)
    #10 0x55d62ce1c3d0 in _start (/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/unistd/libc.test.src.unistd.readlink_test.__build__+0x243d0) (BuildId: ae0527b245e2d2309c0766c70ef97cc20a238829)

Address 0x7ffd8b2ca728 is located in stack of thread T0 at offset 360 in frame
    #0 0x55d62cedc5ef in LlvmLibcReadlinkTest_CreateAndUnlink::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/unistd/readlink_test.cpp:20

  This frame has 9 object(s):
    [32, 48) 'agg.tmp3269'
    [64, 80) 'agg.tmp2262'
    [96, 112) 'agg.tmp1154'
    [128, 144) 'agg.tmp50'
    [160, 184) 'LINK_VAL' (line 23)
    [224, 248) 'LINK' (line 25)
    [288, 320) 'ref.tmp' (line 32)
    [352, 360) 'buf' (line 34) <== Memory access at offset 360 overflows this variable
    [384, 416) 'ref.tmp29' (line 40)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/src/__support/CPP/string_view.h:34:27 in __llvm_libc_19_0_0_git::cpp::string_view::compareMemory(char const*, char const*, unsigned long)
Shadow bytes around the buggy address:
  0x100031651490: 00 00 00 00 00 00 00 00 00 f3 f3 f3 f3 f3 f3 f3
  0x1000316514a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000316514b0: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8 f2 f2

mikhailramalho added a commit that referenced this pull request Jul 5, 2024
mikhailramalho added a commit that referenced this pull request Jul 5, 2024
Reverts #97850 while I investigate the buildbot issue
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
Use sizeof in a string literal instead of a CString so we get the right size when creating the buf array.

We also now use strlen(FILENAME) to get the string lenght when calling readlink and readlinkat.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants