Skip to content
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

translate_open_mode_posix_to_stream: guard against invalid/unsupported oflags #2150

Open
SwooshyCueb opened this issue Nov 27, 2023 · 1 comment

Comments

@SwooshyCueb
Copy link
Member

As noted in #2148 (comment) , translate_open_mode_posix_to_stream in s3_operations.cpp does not guard against invalid/unsupported values passed in via oflag:

std::ios_base::openmode translate_open_mode_posix_to_stream(int oflag, const std::string& call_from) noexcept
{
using std::ios_base;
std::uint64_t thread_id = std::hash<std::thread::id>{}(std::this_thread::get_id());
logger::debug("{}:{} ({}) [[{}]] call_from={} O_WRONLY={}, O_RDWR={}, O_RDONLY={}, O_TRUNC={}, O_CREAT={}, O_APPEND={}",
__FILE__, __LINE__, __FUNCTION__, thread_id, call_from.c_str(),
(oflag & O_ACCMODE) == O_WRONLY, (oflag & O_ACCMODE) == O_RDWR, (oflag & O_ACCMODE) == O_RDONLY,
(oflag & O_TRUNC) != 0, (oflag & O_CREAT) != 0, (oflag & O_APPEND) != 0);
ios_base::openmode mode = 0;
if ((oflag & O_ACCMODE) == O_WRONLY || (oflag & O_ACCMODE) == O_RDWR) {
mode |= ios_base::out;
}
if ((oflag & O_ACCMODE) == O_RDONLY || (oflag & O_ACCMODE) == O_RDWR) {
mode |= ios_base::in;
}
if ((oflag & O_TRUNC) || (oflag & O_CREAT)) {
mode |= ios_base::trunc;
}
if (oflag & O_APPEND) {
mode |= ios_base::app;
mode &= ~ios_base::trunc; // turn off trunc flag
}
return mode;
}

@korydraughn
Copy link
Contributor

This is specifically about making sure the value of O_ACCMODE is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants