Skip to content

fix(toolbox): Correctly print unix sockets with no path#310

Closed
ItsLifeJim wants to merge 1 commit intoreactivemarkets:masterfrom
ItsLifeJim:SDB-10742
Closed

fix(toolbox): Correctly print unix sockets with no path#310
ItsLifeJim wants to merge 1 commit intoreactivemarkets:masterfrom
ItsLifeJim:SDB-10742

Conversation

@ItsLifeJim
Copy link
Contributor

Correctly print unix sockets with no path.

SDB-10742

@ItsLifeJim ItsLifeJim requested a review from a team as a code owner March 3, 2026 07:07
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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

  • Unix Socket Printing: Fixed an issue in print_unix_endpoint where abstract Unix domain sockets with no path were not correctly represented, ensuring they now print as "unix://".
  • Unit Testing: Introduced a new unit test case, ParseStreamUnixEmptyCase, to validate the correct printing of Unix sockets that have no associated path.
Changelog
  • toolbox/net/Endpoint.hpp
    • Modified print_unix_endpoint to correctly handle abstract Unix sockets with an empty path.
    • Changed size_t size to int size for path length calculation and added a check for size <= 0.
  • toolbox/net/Endpoint.ut.cpp
    • Added a new test case ParseStreamUnixEmptyCase to verify the to_string output for Unix sockets with no path.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot]

This comment was marked as outdated.

@ItsLifeJim ItsLifeJim enabled auto-merge (rebase) March 3, 2026 07:26
gemini-code-assist[bot]

This comment was marked as outdated.

Correctly print unix sockets with no path.

SDB-10742
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

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;

Copy link
Contributor

@bnbajwa bnbajwa Mar 3, 2026

Choose a reason for hiding this comment

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

hmm actually i don't even know what << *ep.data() would print?

Copy link
Contributor

@bnbajwa bnbajwa Mar 3, 2026

Choose a reason for hiding this comment

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

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?

@ItsLifeJim ItsLifeJim disabled auto-merge March 3, 2026 12:35
@ItsLifeJim
Copy link
Contributor Author

Closing this work so @bnbajwa can pick this up and complete.

@ItsLifeJim ItsLifeJim closed this Mar 3, 2026
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.

2 participants