From: Sungbae Yoo Date: Thu, 27 Jul 2017 08:09:27 +0000 (+0900) Subject: Fix a bug by that readlink returns not the null-terminated X-Git-Tag: submit/tizen/20170727.084517~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4229e67b917f6db3348049f7e4ca0e8d07fb09e3;p=platform%2Fcore%2Fsecurity%2Fklay.git Fix a bug by that readlink returns not the null-terminated Signed-off-by: Sungbae Yoo Change-Id: I7e4b5545f8acd32926b17b60d6d8f3cc3b039bba --- diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 5fb0f19..69dd909 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -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; }