From 90491ddcbb522c2c9387cf27848adda4e99e1540 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 14 Apr 2016 16:43:22 +0800 Subject: [PATCH] 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 --- src/os/filestore/LFNIndex.cc | 6 ++++++ 1 file changed, 6 insertions(+) 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; -- 2.47.3