fix(toolbox): Correctly print unix sockets with no path#310
fix(toolbox): Correctly print unix sockets with no path#310ItsLifeJim wants to merge 1 commit intoreactivemarkets:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a bug concerning the string representation of abstract Unix domain sockets. Previously, sockets without a defined path were not printed accurately. The changes ensure that such sockets are now correctly formatted as "unix://", improving the reliability of endpoint string conversions. A new unit test has been added to prevent regressions and confirm the fix. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Correctly print unix sockets with no path. SDB-10742
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with printing Unix sockets that have no path. The fix involves adding a check for the endpoint size before attempting to access the path, which correctly handles unbound sockets. Additionally, new unit tests have been added to verify the fix for both unbound sockets and abstract sockets with an empty path. The changes are correct and well-tested.
| os << scheme << '|' << std::string_view{path + 1, path_size - 1}; | ||
| return os; | ||
| } | ||
| os << scheme << *ep.data(); |
There was a problem hiding this comment.
i'm not sure null terminator is guaranteed for non-abstract unix sockets -- in which case this could print a very large sequence of bytes. I think this should be bounded by path_size at least. Maybe something like this?
auto path_view = std::string_view{path, path_size};
if (const auto n = path_view.find('\0'); n != std::string_view::npos) {
path_view = path_view.substr(0, n);
}
os << scheme << path_view;
There was a problem hiding this comment.
hmm actually i don't even know what << *ep.data() would print?
There was a problem hiding this comment.
ok, so it actually invokes this function at bottom, which then calls first function:
template <typename StreamT>
requires toolbox::util::Streamable<StreamT>
StreamT& operator<<(StreamT& os, const sockaddr_un& sa)
{
os << sa.sun_path;
return os;
}
template <typename StreamT>
requires toolbox::util::Streamable<StreamT>
StreamT& operator<<(StreamT& os, const sockaddr& sa)
{
if (sa.sa_family == AF_INET) {
os << reinterpret_cast<const sockaddr_in&>(sa);
} else if (sa.sa_family == AF_INET6) {
os << reinterpret_cast<const sockaddr_in6&>(sa);
} else if (sa.sa_family == AF_UNIX) {
os << reinterpret_cast<const sockaddr_un&>(sa);
} else {
os << "<sockaddr>";
}
return os;
}
os << sa.sun_path
yeh don't think this is right for reason explained above -- i don't think null terminator is guaranteed -- in which case this will print a large number of bytes. this should be fixed as well?
|
Closing this work so @bnbajwa can pick this up and complete. |
Correctly print unix sockets with no path.
SDB-10742