Fix a bug by that readlink returns not the null-terminated 52/140952/3
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 27 Jul 2017 08:09:27 +0000 (17:09 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 27 Jul 2017 08:33:53 +0000 (17:33 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I7e4b5545f8acd32926b17b60d6d8f3cc3b039bba

src/filesystem.cpp

index 5fb0f199c5dc0988d74a491fa0a1e36c15c59a33..69dd909b745941ea02ec175bfadf9e304455a20f 100644 (file)
@@ -383,10 +383,13 @@ void File::chmod(mode_t mode, bool recursive)
 
 const std::string File::readlink() const
 {
-       char buf[PATH_MAX];
-       if (::readlink(path.c_str(), buf, PATH_MAX) == -1) {
+       char buf[PATH_MAX + 1];
+       ssize_t ret = ::readlink(path.c_str(), buf, PATH_MAX);
+       if (ret == -1) {
                throw runtime::Exception(runtime::GetSystemErrorMessage());
        }
+
+       buf[ret] = '\0';
        return buf;
 }