Commit 0157a74b authored by Pavel Labath's avatar Pavel Labath
Browse files

[lldb] Fix an asan error from 27df2d9f

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.
parent 935729e4
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -46,6 +46,18 @@ class CompDirSymLinkTestCase(TestBase):

    @skipIf(hostoslist=["windows"])
    def test_symlink_paths_unset(self):
        pwd_symlink = self.create_src_symlink()
        self.doBuild(pwd_symlink, None)
        src_path = self.getBuildArtifact(_SRC_FILE)
        self.assertRaises(
            AssertionError,
            lldbutil.run_break_set_by_file_and_line,
            self,
            src_path,
            self.line)

    @skipIf(hostoslist=["windows"])
    def test_symlink_paths_empty(self):
        pwd_symlink = self.create_src_symlink()
        self.doBuild(pwd_symlink, "")
        src_path = self.getBuildArtifact(_SRC_FILE)
@@ -67,9 +79,11 @@ class CompDirSymLinkTestCase(TestBase):
    def doBuild(self, pwd_symlink, setting_value):
        self.build(None, None, {'PWD': pwd_symlink})

        self.runCmd(
            "settings set %s '%s'" %
            (_COMP_DIR_SYM_LINK_PROP, setting_value))
        if setting_value:
            cmd = "settings set %s '%s'" % (_COMP_DIR_SYM_LINK_PROP, setting_value)
        else:
            cmd = "settings clear %s"%_COMP_DIR_SYM_LINK_PROP
        self.runCmd(cmd)

        exe = self.getBuildArtifact(_EXE_NAME)
        self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET)
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
  Status error;
  char buf[PATH_MAX];
  ssize_t count = ::readlink(src.GetCString(), buf, sizeof(buf) - 1);
  ssize_t count = ::readlink(src.GetPath().c_str(), buf, sizeof(buf) - 1);
  if (count < 0)
    error.SetErrorToErrno();
  else {