Skip to content

Commit 0157a74

Browse files
committed
[lldb] Fix an asan error from 27df2d9
This error is caused by a combination of a couple of factors: - the test accidentally creating a list with a single (empty) FileSpec instead of an empty list - lldb overzeleously converting empty strings into nullptrs - asan overzeleously validating symlink(2) arguments (the real symlink call would just fail with EFAULT) I fix this by using FileSpec::GetPath instead of GetCString. This avoids the nullptr and also avoids inserting the path into the global string pool. I also enhance the test case to test both empty paths and empty lists.
1 parent 935729e commit 0157a74

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ def test_symlink_paths_set_procselfcwd(self):
4646

4747
@skipIf(hostoslist=["windows"])
4848
def test_symlink_paths_unset(self):
49+
pwd_symlink = self.create_src_symlink()
50+
self.doBuild(pwd_symlink, None)
51+
src_path = self.getBuildArtifact(_SRC_FILE)
52+
self.assertRaises(
53+
AssertionError,
54+
lldbutil.run_break_set_by_file_and_line,
55+
self,
56+
src_path,
57+
self.line)
58+
59+
@skipIf(hostoslist=["windows"])
60+
def test_symlink_paths_empty(self):
4961
pwd_symlink = self.create_src_symlink()
5062
self.doBuild(pwd_symlink, "")
5163
src_path = self.getBuildArtifact(_SRC_FILE)
@@ -67,9 +79,11 @@ def create_src_symlink(self):
6779
def doBuild(self, pwd_symlink, setting_value):
6880
self.build(None, None, {'PWD': pwd_symlink})
6981

70-
self.runCmd(
71-
"settings set %s '%s'" %
72-
(_COMP_DIR_SYM_LINK_PROP, setting_value))
82+
if setting_value:
83+
cmd = "settings set %s '%s'" % (_COMP_DIR_SYM_LINK_PROP, setting_value)
84+
else:
85+
cmd = "settings clear %s"%_COMP_DIR_SYM_LINK_PROP
86+
self.runCmd(cmd)
7387

7488
exe = self.getBuildArtifact(_EXE_NAME)
7589
self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET)

lldb/source/Host/posix/FileSystemPosix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
4343
Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
4444
Status error;
4545
char buf[PATH_MAX];
46-
ssize_t count = ::readlink(src.GetCString(), buf, sizeof(buf) - 1);
46+
ssize_t count = ::readlink(src.GetPath().c_str(), buf, sizeof(buf) - 1);
4747
if (count < 0)
4848
error.SetErrorToErrno();
4949
else {

0 commit comments

Comments
 (0)