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 code issues in object manager that are reported by scanning tool #3649

Merged

Conversation

zhijunfu
Copy link
Contributor

Fix some code issues found by code scanning tool:

1. Macro compares unsigned to 0(NO_EFFECT)

CWE570: An unsigned value can never be less than 0
This greater-than-or-equal-to-zero comparison of an unsigned value is always true. "this->create_buffer_state_[object_id].num_seals_remaining >= 0UL".

~/ray/src/ray/object_manager/object_buffer_pool.cc: ray::ObjectBufferPool::SealChunk(const ray::UniqueID &, unsigned long)

2. Inferred misuse of enum(MIXED_ENUMS)

CWE398: An integer expression which was inferred to have an enum type is mixed with a different enum type
This case, "static_cast(ray::object_manager::protocol::MessageType::PushRequest)", implies the effective type of "message_type" is "ray::object_manager::protocol::MessageType".

~/ray/src/ray/object_manager/object_manager.cc: ray::ObjectManager::ProcessClientMessage(std::shared_ptr> &, long, const unsigned char *)

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10448/
Test FAILed.

switch (message_type) {
case static_cast<int64_t>(object_manager_protocol::MessageType::PushRequest): {
if (static_cast<protocol::MessageType>(message_type) ==
protocol::MessageType::DisconnectClient) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems problematic that message_type can have type either protocol::MessageType or object_manager_protocol::MessageType because those two enums could have overlapping values. For example, couldn't protocol::MessageType::DisconnectClient be the same integer value as some value in object_manager_protocol::MessageType?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's right. Currently object_manager_protocol::MessageType doesn't have the same value as protocol::MessageType::DisconnectClient. But we may accidentally introduce bugs in the future when we add new values to object_manager_protocol::MessageType.

I don't know what's the reason why this message_type uses mixed types. Can we also add a DisconnectClient to object_manager_protocol::MessageType? @zhijunfu

If that cannot be easily fixed, we should at least add a warning comment in object_manager.fbs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is indeed a problem, although it's not brought in by this PR.
How about we support both protocol::MessageType::DisconnectClient and object_manager_protocol::MessageType::DisconnectClient? Then two different sets of MessageType enums can be totally decoupled.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, that would be nicer.

@robertnishihara
Copy link
Collaborator

Looks like there are some linting errors.

ReceiveFreeRequest(conn, message);
break;
}
case static_cast<int64_t>(protocol::MessageType::DisconnectClient): {
case object_manager_protocol::MessageType::DisconnectClient: {
Copy link
Contributor

Choose a reason for hiding this comment

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

the below TDO can be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

done

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10478/
Test PASSed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10480/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10483/
Test FAILed.

@robertnishihara robertnishihara merged commit 382b138 into ray-project:master Dec 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants