Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

HHVM-178, HHVM-179, HHVM-180: Range checks for WriteConcern, Binary, and Timestamp #69

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 12 additions & 0 deletions ext_mongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ final class Binary implements Type, \Serializable

public function __construct(private string $data, private int $type)
{
if ( $type < 0 || $type > 255 )
Copy link
Member

Choose a reason for hiding this comment

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

UINT8_MAX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't exist as a PHP user land exported value annoyingly.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I missed the fact that this was in PHP. No worries, then.

{
throw new \MongoDB\Driver\Exception\InvalidArgumentException( "Expected type to be an unsigned 8-bit integer, {$type} given" );
}
}

public function getType()
Expand Down Expand Up @@ -758,6 +762,14 @@ final class Timestamp implements Type, \Serializable

public function __construct(private int $increment, private int $timestamp)
{
if ( $increment < 0 || $increment > 4294967295 )
{
throw new \MongoDB\Driver\Exception\InvalidArgumentException( "Expected increment to be an unsigned 32-bit integer, {$increment} given" );
}
if ( $timestamp < 0 || $timestamp > 4294967295 )
Copy link
Member

Choose a reason for hiding this comment

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

UINT32_MAX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't exist as a PHP user land exported value annoyingly.

{
throw new \MongoDB\Driver\Exception\InvalidArgumentException( "Expected timestamp to be an unsigned 32-bit integer, {$timestamp} given" );
}
}

public function __toString() : string
Expand Down
12 changes: 12 additions & 0 deletions src/MongoDB/Driver/WriteConcern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ void HHVM_METHOD(MongoDBDriverWriteConcern, __construct, const Variant &w, const
throw MongoDriver::Utils::throwInvalidArgumentException((char*) wtimeout_error.toString().c_str());
}

if (wtimeout_int > INT32_MAX) {
StringBuffer buf;

buf.printf(
"Expected wtimeout to be <= %d, %ld given",
INT32_MAX,
wtimeout_int
);
Variant wtimeout_error = buf.detach();
throw MongoDriver::Utils::throwInvalidArgumentException((char*) wtimeout_error.toString().c_str());
}

mongoc_write_concern_set_wtimeout(data->m_write_concern, wtimeout_int);
}

Expand Down