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

ibus-daemon --address=unix:path=something fails with EADDRINUSE because we mkdir it #2363

Closed
martinetd opened this issue Dec 7, 2021 · 5 comments

Comments

@martinetd
Copy link

fedora34, ibus version 1.5.23

Issue description:
trying to run ibus-daemon with --address=unix:path=/some/path fails because we create /some/path before trying to connect the socket.
incidentally dbus-daemon also segfaults when trying to print a log at that point, I didn't check why as I'm in the middle of debugging something else...

Steps to reproduce:
1.

$ ibus-daemon --xim  --replace --address=unix:path=/run/user/1000/bus --verbose

(ibus-daemon:28444): IBUS-ERROR **: 21:37:28.530: g_dbus_server_new_sync() is failed with address unix:path=/run/user/1000/bus and guid c6fb8acb152b7e9d29a1831661af5588: Error binding to address (GUnixSocketAddress): Address already in use
Trace/breakpoint trap (core dumped)

Reason:
The problem is in bus_server_init() the code has the same logic for unix:tmpdir/dir and path:

#define IF_GET_UNIX_DIR(prefix)                                         \
    if (g_str_has_prefix (socket_address, (prefix))) {                  \
        unix_dir = g_strdup (socket_address + strlen (prefix));         \
    }

    IF_GET_UNIX_DIR (IBUS_UNIX_TMPDIR)
    else
    IF_GET_UNIX_DIR (IBUS_UNIX_PATH)
    else
    IF_GET_UNIX_DIR (IBUS_UNIX_ABSTRACT)
    else
    IF_GET_UNIX_DIR (IBUS_UNIX_DIR)
    else {
        g_error ("Your socket address \"%s\" does not correspond with "
                 "one of the following formats; "
                 IBUS_UNIX_TMPDIR "DIR, " IBUS_UNIX_PATH "FILE, "
                 IBUS_UNIX_ABSTRACT "FILE, " IBUS_UNIX_DIR "DIR.",
                 socket_address);
    }
    if (!g_file_test (unix_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
        /* Require mkdir for BSD system.
         * The mode 0700 can eliminate malicious users change the mode.
         * `chmod` runs for the last directory only not to change the modes
         * of the parent directories. E.g. "/tmp/ibus".
         */
        errno = 0;
        if (g_mkdir_with_parents (unix_dir, 0700) != 0) {
            g_error ("mkdir is failed in: %s: %s",
                     unix_dir, g_strerror (errno));
        }
    }

the IF_GET_UNIX_DIR for IBUS_UNIX_PATH should strip the last component of the path before creating only parent directories.

If nobody care I'll send a PR eventually, for now I've worked around the issue by using unix:dir=...

fujiwarat added a commit that referenced this issue Feb 3, 2022
IBus ran mkdir for socket paths for --address=unix:path
but should does the socket directories instead.

BUG=#2363
@fujiwarat fujiwarat self-assigned this Feb 3, 2022
@fujiwarat fujiwarat added this to the 1.5.26 milestone Feb 3, 2022
@fujiwarat
Copy link
Member

Thank you for the report.

@martinetd
Copy link
Author

thanks for the fix!

While I am looking at it ( 787b564 ), abstract unix socket probably should not require a unix dir? I would expect a path such as "\0something" where the \0 is prepended by ibus when using the abstract prefix, and since it is not on filesystem mkdir is not required.

The \0 is the @ in ss -x

@fujiwarat
Copy link
Member

Do you know how the abstract socket works in BSD system?

a141a14

@martinetd
Copy link
Author

man 7 unix states "The abstract socket namespace is a nonportable Linux extension." so it is safe to say they wouldn't be usable on BSD systems.
I'm sorry, I don't normally run any BSD so cannot say if there is an equivalent, it's probably fine to error out in this case? it's not the default, so it's the user's responsibility if they tried to use one.

@fujiwarat
Copy link
Member

Thank you. I follow your suggestion and will update server.c

fujiwarat added a commit that referenced this issue Feb 3, 2022
IBus ran mkdir for unix abstract sockets for --address=unix:abstract
but should not need to mkdir.

BUG=#2363
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants