From: Tomasz Iwanek Date: Thu, 28 Apr 2016 09:13:09 +0000 (+0200) Subject: Fallback to lstat() if readdir() fails to give type in reference checking X-Git-Tag: accepted/tizen/common/20160518.124940~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9024fb9edc20217b9367f53274fecad793985c5;p=platform%2Fcore%2Fsecurity%2Fcert-svc.git Fallback to lstat() if readdir() fails to give type in reference checking Some filesytem types may not set d_type field to indicate the type of directory entry. This code adds workaround to try to stat file if directory entry type is unknown. This will be basicly needed to check file references when we are using tzip filesystem for storing tizen package files. Although tzip implements readdir(), it is not setting d_type. Correct behaviour of caller is to handle value DT_UNKNOWN. Change-Id: I45642ae5d50a3d3f3fbc09e41f54e4a118037e1d --- diff --git a/vcore/vcore/ReferenceValidator.cpp b/vcore/vcore/ReferenceValidator.cpp index 3b59682..509ba1b 100644 --- a/vcore/vcore/ReferenceValidator.cpp +++ b/vcore/vcore/ReferenceValidator.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include @@ -177,6 +179,21 @@ ReferenceValidator::Result ReferenceValidator::Impl::dfsCheckDirectories( continue; } + if (result->d_type == DT_UNKNOWN) { + // try to stat inode when readdir is not returning known type + std::string path = currentDir + "/" + result->d_name; + struct stat s; + if (lstat(path.c_str(), &s) != 0) { + closedir(dirp); + return ERROR_LSTAT; + } + if (S_ISREG(s.st_mode)) { + result->d_type = DT_REG; + } else if (S_ISDIR(s.st_mode)) { + result->d_type = DT_DIR; + } + } + if (currentDir == m_dirpath && result->d_type == DT_REG && !strcmp(result->d_name, SPECIAL_SYMBOL_AUTHOR_SIGNATURE_FILE) && isAuthorSignature) diff --git a/vcore/vcore/ReferenceValidator.h b/vcore/vcore/ReferenceValidator.h index cd819c3..f604b42 100644 --- a/vcore/vcore/ReferenceValidator.h +++ b/vcore/vcore/ReferenceValidator.h @@ -41,7 +41,8 @@ class ReferenceValidator : VcoreDPL::Noncopyable ERROR_REFERENCE_NOT_FOUND, ERROR_DECODING_URL, ERROR_OUTBOUND_LNK, - ERROR_READING_LNK + ERROR_READING_LNK, + ERROR_LSTAT }; ReferenceValidator(const std::string &dirpath);