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

Fix shared memory read mode potential issue #2032

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion Foundation/src/SharedMemory_POSIX.cpp
Expand Up @@ -32,7 +32,7 @@ SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, Sh
_access(mode),
_name("/"),
_fileMapped(false),
_server(server)
_server((mode == SharedMemory::AM_WRITE))
Copy link
Member

@aleks-f aleks-f Dec 19, 2017

Choose a reason for hiding this comment

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

if bool server is not needed/used, it should be removed from the signature and documentation updated

{
#if POCO_OS == POCO_OS_HPUX
_name.append("tmp/");
Expand All @@ -58,6 +58,17 @@ SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, Sh
_fd = -1;
::shm_unlink(_name.c_str());
throw SystemException("Cannot resize shared memory object", _name);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

struct stat buf;
if (fstat(_fd, &buf) == -1) {
::close(_fd);
_fd = -1;
::shm_unlink(_name.c_str());
throw SystemException("Cannot check file information", _name);
}
if (_size > buf.st_size) {
_size = buf.st_size
}
}
map(addrHint);
}
Expand Down