Skip to content
Open
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
19 changes: 15 additions & 4 deletions src/jrd/replication/Applier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ namespace

const string& getAtomString()
{
const auto pos = getInt32();
const ULONG pos = static_cast<ULONG>(getInt32());

if (pos >= m_atoms.getCount())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer explicit checks with a signed pos:

if (pos < 0 || pos >= m_atoms.getCount())

malformed();

return m_atoms[pos];
}

const MetaString getAtomMetaName()
{
const auto pos = getInt32();
const ULONG pos = static_cast<ULONG>(getInt32());

if (pos >= m_atoms.getCount())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

malformed();

return m_atoms[pos];
}

Expand All @@ -154,7 +162,7 @@ namespace
{
const auto length = getInt32();

if (m_data + length > m_end)
if (length <= 0 || m_end - m_data < length)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd allow zero-length strings even if it looks impossible now.

malformed();

const string str((const char*) m_data, length);
Expand All @@ -164,7 +172,7 @@ namespace

const UCHAR* getBinary(ULONG length)
{
if (m_data + length > m_end)
if (m_end - m_data < length)
malformed();

const auto ptr = m_data;
Expand All @@ -185,6 +193,9 @@ namespace
void defineAtom()
{
const auto length = getByte();
if (length <= 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

malformed();

const auto ptr = getBinary(length);
const MetaString name((const char*) ptr, length);
m_atoms.add(name);
Expand Down
Loading