Skip to content

DirectConnection.listen() NPE in SASL.doResponse with sd-bus peer #294

Open

Description

@Monkopedia

DirectConnection.listen() crashes with NPE in SASL.doResponse when peer is sd-bus

Summary

dbus-java server-side direct bus listener crashes with:

java.lang.NullPointerException
  at java.text.RuleBasedCollator.compare
  at org.freedesktop.dbus.connections.SASL.doResponse(SASL.java:369)

when the connecting peer is native sd-bus (C/libsystemd).

This looks like a null-handling bug in SASL response processing for AUTH EXTERNAL.

Environment

  • dbus-java-core: 5.1.1
  • dbus-java-transport-junixsocket: 5.1.1
  • Java: 21.0.10
  • OS: Linux x86_64 (6.18.7-arch1-1)
  • Native peer: libsystemd 259

Minimal Reproducer

I created a standalone repro with:

  • Java server: DirectConnectionBuilder.forAddress("unix:path=...,listen=true").build(); connection.listen();
  • C client using sd-bus:
    • sd_bus_new
    • sd_bus_set_address("unix:path=...")
    • sd_bus_start

Run:

./repro/dbus-java-sasl-npe/run-repro.sh

Repro files:

  • repro/dbus-java-sasl-npe/server/src/main/java/repro/DbusJavaServer.java
  • repro/dbus-java-sasl-npe/client/sd_bus_client.c
  • repro/dbus-java-sasl-npe/run-repro.sh

Actual Result

Server exits with:

Exception in thread "main" java.lang.NullPointerException
    at java.base/java.text.RuleBasedCollator.compare(RuleBasedCollator.java:359)
    at org.freedesktop.dbus.connections.SASL.doResponse(SASL.java:369)
    at org.freedesktop.dbus.connections.SASL.auth(SASL.java:625)
    at org.freedesktop.dbus.connections.transports.AbstractTransport.authenticate(AbstractTransport.java:254)
    at org.freedesktop.dbus.connections.transports.AbstractTransport.internalConnect(AbstractTransport.java:230)
    at org.freedesktop.dbus.connections.transports.AbstractTransport.listen(AbstractTransport.java:215)
    at org.freedesktop.dbus.connections.impl.DirectConnection.listen(DirectConnection.java:66)
    at repro.DbusJavaServer.main(DbusJavaServer.java:47)

Expected Result

DirectConnection.listen() should not crash; it should either authenticate successfully or reject auth without throwing NPE.

Notes

In the D-Bus auth protocol, AUTH initial response is optional. A missing initial payload should be handled safely:

Activity

  1. Monkopedia commented on Feb 15, 2026

    @Monkopedia
    Author

    I published the complete standalone reproducer as a public gist:

    https://gist.github.com/Monkopedia/dbe1a170944c69c592aa2b75c41a019a

    It contains the Java server, C sd-bus client, and run script from the issue description.

  2. hypfvieh commented on Feb 15, 2026

    @hypfvieh
    Owner

    Thanks for the report, the provided details and the code to reproduce.

    I updated the SASL code in dbus-java 5.x and 6.x to fix the NPE.

  3. tory-kk commented on Sep 10, 2026

    @tory-kk

    Hello @hypfvieh,
    We are facing the same issue with github.com/godbus/dbus/v5 v5.2.2 client.
    I can see that PR #295 was merged. However, it has not been released yet. Is there an estimated release date?

  4. hypfvieh commented on Sep 12, 2026

    @hypfvieh
    Owner

    sorry, I forgot to create the release for 5.x 😢

    I did the release now, I hope it works. As usual, it will take some time until it is published by Maven Central...

  5. tory-kk commented on Sep 21, 2026

    @tory-kk

    Hello @hypfvieh,
    Sorry for the delay, just tested version 5.2.1. The new version does not produce NPE, however, it seems incompatible with the newer approach for AUTH_EXTERNAL messages where clients no longer send data block. I am referring to godbus/dbus client (DBus for Golang) changes introduced in godbus/dbus@31b5df7

    Logs on the dbus-java side:

    org.freedesktop.dbus.exceptions.SocketClosedException: Stream unexpectedly short (broken pipe)
            at org.freedesktop.dbus.connections.SASL.receive(SASL.java:247)
            at org.freedesktop.dbus.connections.SASL.auth(SASL.java:623)
            at org.freedesktop.dbus.connections.transports.AbstractTransport.authenticate(AbstractTransport.java:254)
            at org.freedesktop.dbus.connections.transports.AbstractTransport.internalConnect(AbstractTransport.java:230)
            at org.freedesktop.dbus.connections.transports.AbstractTransport.listen(AbstractTransport.java:215)
            at org.freedesktop.dbus.bin.EmbeddedDBusDaemon.startListening(EmbeddedDBusDaemon.java:319)
            at org.freedesktop.dbus.bin.EmbeddedDBusDaemon.startInForeground(EmbeddedDBusDaemon.java:91)
            at org.freedesktop.dbus.bin.DBusDaemon.main(DBusDaemon.java:409)
            ...
            at java.base/java.lang.Thread.run(Thread.java:840)
    

    Are there any solutions for such a case?

  6. hypfvieh commented on Sep 21, 2026

    @hypfvieh
    Owner

    I added a patch for 5x and 6x, you may try the most recent snapshot (6x only, sorry) or build the library from source. If this is working for you I can create another release for 5x.

  7. tory-kk commented on Sep 22, 2026

    @tory-kk

    Tried 5.2.2-SNAPSHOT version (built locally from master-5x branch) - everything works as expected :)

  8. tory-kk commented on Sep 25, 2026

    @tory-kk

    @hypfvieh Could you please create a new release for the 5.x version?

  9. hypfvieh commented on Sep 26, 2026

    @hypfvieh
    Owner

    @tory-kk release is on its way (takes some time as usual)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions