Skip to content

Fix Time-of-check time-of-use filesystem race condition and Likely overrunning write #12183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fdbrpc/HTTP.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::string awsV4URIEncode(const std::string& s, bool encodeSlash) {
else if (c == '/')
o.append(encodeSlash ? "%2F" : "/");
else {
sprintf(buf, "%%%.02X", c);
snprintf(buf, sizeof(buf), "%%%.02X", c);
o.append(buf);
}
}
Expand Down
12 changes: 10 additions & 2 deletions fdbrpc/libeio/eio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,9 +2232,17 @@ static void eio_execute(etp_worker* self, eio_req* req) {
case EIO_UNLINK:
req->result = unlink(path);
break;
case EIO_RMDIR:
req->result = rmdir(path);
case EIO_RMDIR: {
int dirfd = open(path, O_DIRECTORY | O_RDONLY);
if (dirfd == -1) {
req->result = -1;
req->errorno = errno;
} else {
req->result = rmdir(path);
Copy link
Contributor

@jzhou77 jzhou77 Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performing the rmdir operation using the file descriptor, ensuring the operation applies to the intended directory.

I'm confused. The dirfd is not used?

This doesn't seem to have the TOCTOU problem.

close(dirfd);
}
break;
}
case EIO_MKDIR:
req->result = mkdir(path, (mode_t)req->int2);
break;
Expand Down