Skip to content

Commit

Permalink
Merge changes I8d2bd67d,I704522b2
Browse files Browse the repository at this point in the history
* changes:
  FsCrypt: silently skip "." and ".." when loading keys
  Utils: add IsDotOrDotDot() and use it in the appropriate places
  • Loading branch information
ebiggers authored and Gerrit Code Review committed Nov 3, 2020
2 parents 4a969db + 6b84039 commit 27f3ab8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 4 additions & 0 deletions FsCrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ using android::base::StartsWith;
using android::base::StringPrintf;
using android::fs_mgr::GetEntryForMountPoint;
using android::vold::BuildDataPath;
using android::vold::IsDotOrDotDot;
using android::vold::IsFilesystemSupported;
using android::vold::kEmptyAuthentication;
using android::vold::KeyBuffer;
Expand Down Expand Up @@ -140,6 +141,7 @@ static std::vector<std::string> get_ce_key_paths(const std::string& directory_pa
}
break;
}
if (IsDotOrDotDot(*entry)) continue;
if (entry->d_type != DT_DIR || entry->d_name[0] != 'c') {
LOG(DEBUG) << "Skipping non-key " << entry->d_name;
continue;
Expand Down Expand Up @@ -391,6 +393,7 @@ static bool load_all_de_keys() {
}
break;
}
if (IsDotOrDotDot(*entry)) continue;
if (entry->d_type != DT_DIR || !is_numeric(entry->d_name)) {
LOG(DEBUG) << "Skipping non-de-key " << entry->d_name;
continue;
Expand Down Expand Up @@ -973,6 +976,7 @@ static bool destroy_volume_keys(const std::string& directory_path, const std::st
}
break;
}
if (IsDotOrDotDot(*entry)) continue;
if (entry->d_type != DT_DIR || entry->d_name[0] == '.') {
LOG(DEBUG) << "Skipping non-user " << entry->d_name;
continue;
Expand Down
4 changes: 1 addition & 3 deletions MoveStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ static bool pushBackContents(const std::string& path, std::vector<std::string>&
bool found = false;
struct dirent* ent;
while ((ent = readdir(dirp.get())) != NULL) {
if ((!strcmp(ent->d_name, ".")) || (!strcmp(ent->d_name, ".."))) {
continue;
}
if (IsDotOrDotDot(*ent)) continue;
auto subdir = path + "/" + ent->d_name;
found |= pushBackContents(subdir, cmd, searchLevels - 1);
}
Expand Down
14 changes: 6 additions & 8 deletions Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,7 @@ int64_t calculate_dir_size(int dfd) {
int subfd;

/* always skip "." and ".." */
if (name[0] == '.') {
if (name[1] == 0) continue;
if ((name[1] == '.') && (name[2] == 0)) continue;
}
if (IsDotOrDotDot(*de)) continue;

subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (subfd >= 0) {
Expand Down Expand Up @@ -1256,6 +1253,10 @@ status_t UnmountTree(const std::string& mountPoint) {
return OK;
}

bool IsDotOrDotDot(const struct dirent& ent) {
return strcmp(ent.d_name, ".") == 0 || strcmp(ent.d_name, "..") == 0;
}

static status_t delete_dir_contents(DIR* dir) {
// Shamelessly borrowed from android::installd
int dfd = dirfd(dir);
Expand All @@ -1269,10 +1270,7 @@ static status_t delete_dir_contents(DIR* dir) {
const char* name = de->d_name;
if (de->d_type == DT_DIR) {
/* always skip "." and ".." */
if (name[0] == '.') {
if (name[1] == 0) continue;
if ((name[1] == '.') && (name[2] == 0)) continue;
}
if (IsDotOrDotDot(*de)) continue;

android::base::unique_fd subfd(
openat(dfd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC));
Expand Down
2 changes: 2 additions & 0 deletions Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ bool IsVirtioBlkDevice(unsigned int major);
status_t UnmountTreeWithPrefix(const std::string& prefix);
status_t UnmountTree(const std::string& mountPoint);

bool IsDotOrDotDot(const struct dirent& ent);

status_t DeleteDirContentsAndDir(const std::string& pathname);
status_t DeleteDirContents(const std::string& pathname);

Expand Down

0 comments on commit 27f3ab8

Please sign in to comment.