mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
fuse_readlink: always null-terminate buffer
Old code only null-terminated when the returned/copied length was strictly less than the caller-supplied bufsize_, leaving the buffer unterminated on an exact-fill. Since buf_ is consumed as a C string, reserve one byte for the terminator up front and unconditionally terminate.
This commit is contained in:
parent
1e8e313db0
commit
02a1b2d014
1 changed files with 4 additions and 6 deletions
|
|
@ -40,12 +40,11 @@ _readlink_core_standard(const fs::path &fullpath_,
|
|||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::readlink(fullpath_,buf_,bufsize_);
|
||||
rv = fs::readlink(fullpath_,buf_,(bufsize_ - 1));
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
if((size_t)rv < bufsize_)
|
||||
buf_[rv] = '\0';
|
||||
buf_[rv] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -71,10 +70,9 @@ _readlink_core_symlinkify(const fs::path &fullpath_,
|
|||
if(!symlinkify::can_be_symlink(st,symlinkify_timeout_))
|
||||
return ::_readlink_core_standard(fullpath_,buf_,bufsize_);
|
||||
|
||||
n = std::min(fullpath_str.size(),bufsize_);
|
||||
n = std::min(fullpath_str.size(),(bufsize_ - 1));
|
||||
memcpy(buf_,fullpath_str.c_str(),n);
|
||||
if(n < bufsize_)
|
||||
buf_[n] = '\0';
|
||||
buf_[n] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue