Merge changes from topic "dir_fix" into main
* changes:
Use updated headers in libfuse
Correctly handle non-NULL terminated fuse_dirents
Fix fuse-bpf can lead to folders not be viewable erroneously
diff --git a/jni/FuseDaemon.cpp b/jni/FuseDaemon.cpp
index 68a1463..e5fb23e 100644
--- a/jni/FuseDaemon.cpp
+++ b/jni/FuseDaemon.cpp
@@ -1962,7 +1962,7 @@
struct fuse* fuse = get_fuse(req);
char buf[READDIR_BUF];
struct fuse_read_out* fro = (struct fuse_read_out*)(buf);
- size_t used = sizeof(*fro);
+ size_t used = 0;
char* dirents_out = (char*)(fro + 1);
ATRACE_CALL();
@@ -1981,10 +1981,12 @@
for (off_t in = 0; in < size_out;) {
struct fuse_dirent* dirent_in = (struct fuse_dirent*)((char*)dirents_in + in);
- struct fuse_dirent* dirent_out = (struct fuse_dirent*)((char*)dirents_out + fro->size);
+ struct fuse_dirent* dirent_out = (struct fuse_dirent*)((char*)dirents_out + used);
struct stat stats;
int err;
- std::string child_path = path + "/" + dirent_in->name;
+
+ std::string child_name(dirent_in->name, dirent_in->namelen);
+ std::string child_path = path + "/" + child_name;
in += sizeof(*dirent_in) + round_up(dirent_in->namelen, sizeof(uint64_t));
err = stat(child_path.c_str(), &stats);
@@ -1992,14 +1994,13 @@
((stats.st_mode & 0001) || ((stats.st_mode & 0010) && req->ctx.gid == stats.st_gid) ||
((stats.st_mode & 0100) && req->ctx.uid == stats.st_uid) ||
fuse->mp->isUidAllowedAccessToDataOrObbPath(req->ctx.uid, child_path) ||
- strcmp(dirent_in->name, ".nomedia") == 0)) {
+ child_name == ".nomedia")) {
*dirent_out = *dirent_in;
- strcpy(dirent_out->name, dirent_in->name);
- fro->size += sizeof(*dirent_out) + round_up(dirent_out->namelen, sizeof(uint64_t));
+ strcpy(dirent_out->name, child_name.c_str());
+ used += sizeof(*dirent_out) + round_up(dirent_out->namelen, sizeof(uint64_t));
}
}
- used += fro->size;
- fuse_reply_buf(req, buf, used);
+ fuse_reply_buf(req, buf, sizeof(*fro) + used);
}
static void pf_readdirplus(fuse_req_t req,