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

Address comments from PR 812: Add check before deserializing messages #816

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
6 changes: 2 additions & 4 deletions common/events_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ struct serialization
int
deserialize(const string& s, Map& data)
{
if (s.size() < 2) { // zmq identifying message of length 1
return 0;
}
try {
istringstream ss(s);
boost::archive::text_iarchive iarch(ss);
Expand Down Expand Up @@ -312,7 +309,8 @@ struct serialization
more = 0;
zmq_msg_init(&msg);
int rc = zmq_msg_recv(&msg, sock, flag);
if (rc != -1) {
int msg_size = static_cast<int>(zmq_msg_size(&msg));
zbud-msft marked this conversation as resolved.
Show resolved Hide resolved
zbud-msft marked this conversation as resolved.
Show resolved Hide resolved
if (rc != -1 && msg_size > 1) {
size_t more_size = sizeof (more);

zmq_getsockopt (sock, ZMQ_RCVMORE, &more, &more_size);
Expand Down
11 changes: 8 additions & 3 deletions tests/events_common_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ TEST(events_common, send_recv)
void *sock_p1 = zmq_socket (zmq_ctx, ZMQ_PAIR);
EXPECT_EQ(0, zmq_bind (sock_p1, path));

string source("Hello"), source1, source2("#");
string source("Hello"), source1, source2, source3;
Copy link
Contributor

Choose a reason for hiding this comment

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

The Ut can pass without any code change in zmq_read_part, which means the UT change is not necessary.

Copy link
Contributor

@liuh-80 liuh-80 Sep 12, 2023

Choose a reason for hiding this comment

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

By read the eventd code, I found it's using event_service.
So you need create new UT to cover channel_read in https://github.com/sonic-net/sonic-swss-common/blob/master/tests/events_service_ut.cpp

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussion offline ,suggest revert this PR.


map<string, string> m = {{"foo", "bar"}, {"hello", "world"}, {"good", "day"}};
map<string, string> m1, m2;
map<string, string> m1, m2, m3;

EXPECT_EQ(0, zmq_message_send(sock_p0, source, m));

EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source1, m1));

EXPECT_EQ(source, source1);
EXPECT_EQ(m, m1);


EXPECT_EQ(0, zmq_message_send(sock_p0, source2, m2));
EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source3, m3));

EXPECT_EQ(0, deserialize(source2, m2));
EXPECT_EQ(source2, source3);
EXPECT_EQ(m2, m3);

zmq_close(sock_p0);
zmq_close(sock_p1);
Expand Down