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

Properly checking the return value of ipc_sendrecv_with_fds #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 19 additions & 3 deletions msgq/visionipc/visionipc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ bool VisionIpcClient::connect(bool blocking){
}
// Send stream type to server to request FDs
int r = ipc_sendrecv_with_fds(true, socket_fd, &type, sizeof(type), nullptr, 0, nullptr);
if (r <= 0) {
close(socket_fd);
return false;
}

assert(r == sizeof(type));

// Get FDs
int fds[VISIONIPC_MAX_FDS];
VisionBuf bufs[VISIONIPC_MAX_FDS];
r = ipc_sendrecv_with_fds(false, socket_fd, &bufs, sizeof(bufs), fds, VISIONIPC_MAX_FDS, &num_buffers);
if (r <= 0) {
close(socket_fd);
return false;
}

assert(num_buffers >= 0);
assert(r == sizeof(VisionBuf) * num_buffers);

// Import buffers
Expand Down Expand Up @@ -122,11 +130,19 @@ std::set<VisionStreamType> VisionIpcClient::getAvailableStreams(const std::strin
// Send VISION_STREAM_MAX to server to request available streams
int request = VISION_STREAM_MAX;
int r = ipc_sendrecv_with_fds(true, socket_fd, &request, sizeof(request), nullptr, 0, nullptr);
assert(r == sizeof(request));
if (r <= 0) {
close(socket_fd);
return {};
}

VisionStreamType available_streams[VISION_STREAM_MAX] = {};
r = ipc_sendrecv_with_fds(false, socket_fd, &available_streams, sizeof(available_streams), nullptr, 0, nullptr);
assert((r >= 0) && (r % sizeof(VisionStreamType) == 0));
if (r <= 0) {
close(socket_fd);
return {};
}

assert((r % sizeof(VisionStreamType)) == 0);
close(socket_fd);
return std::set<VisionStreamType>(available_streams, available_streams + r / sizeof(VisionStreamType));
}
Expand Down
2 changes: 1 addition & 1 deletion msgq/visionipc/visionipc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void VisionIpcServer::listener(){
}

if (buffers.count(type) <= 0) {
std::cout << "got request for invalid buffer type: " << type << std::endl;
// std::cout << "got request for invalid buffer type: " << type << std::endl;
close(fd);
continue;
}
Expand Down
Loading