From: xie xingguo Date: Thu, 14 Apr 2016 08:43:22 +0000 (+0800) Subject: os/filestore: add sanity check for stat() syscall X-Git-Tag: v11.0.0~855^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=90491ddcbb522c2c9387cf27848adda4e99e1540;p=ceph.git os/filestore: add sanity check for stat() syscall The syscall stat() may fail here, the hardlink output shall be assigned a rubbish value as a result and mislead caller. Signed-off-by: xie xingguo --- diff --git a/src/os/filestore/LFNIndex.cc b/src/os/filestore/LFNIndex.cc index 1994d5ac1ee9..e22ff58e8c5c 100644 --- a/src/os/filestore/LFNIndex.cc +++ b/src/os/filestore/LFNIndex.cc @@ -786,6 +786,12 @@ int LFNIndex::lfn_get_name(const vector &path, if (hardlink) { struct stat st; r = ::stat(candidate_path.c_str(), &st); + if (r < 0) { + if (errno == ENOENT) + *hardlink = 0; + else + return -errno; + } *hardlink = st.st_nlink; } return 0;