From 26d297920acbe476629d48656efad1e5b62e2253 Mon Sep 17 00:00:00 2001 From: John Mercier Date: Thu, 26 Dec 2024 15:05:33 -0500 Subject: [PATCH] Fixed xauth parsing --- README.md | 4 +++ .../moaxcp/x11/protocol/XAuthority.java | 33 ++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a613eba9..e7ed6309 100644 --- a/README.md +++ b/README.md @@ -435,6 +435,10 @@ https://www.x.org/releases/X11R7.6/doc/libXtst/recordlib.html # versions +## 0.20.0 + +Fixing XAuthority parsing following the format described [here](https://gitlab.freedesktop.org/xorg/lib/libxau/-/tree/master?ref_type=heads). + ## 0.19.0 * Added support for little-endian and made it default to match the server default. diff --git a/x11-protocol/x11-protocol-core/src/main/java/com/github/moaxcp/x11/protocol/XAuthority.java b/x11-protocol/x11-protocol-core/src/main/java/com/github/moaxcp/x11/protocol/XAuthority.java index 90f15f77..6aa897ea 100644 --- a/x11-protocol/x11-protocol-core/src/main/java/com/github/moaxcp/x11/protocol/XAuthority.java +++ b/x11-protocol/x11-protocol-core/src/main/java/com/github/moaxcp/x11/protocol/XAuthority.java @@ -1,5 +1,9 @@ package com.github.moaxcp.x11.protocol; +import lombok.NonNull; +import lombok.ToString; +import lombok.Value; + import java.io.*; import java.net.InetAddress; import java.net.UnknownHostException; @@ -7,9 +11,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import lombok.NonNull; -import lombok.ToString; -import lombok.Value; import static com.github.moaxcp.x11.protocol.ParametersCheck.requireNonEmpty; import static com.github.moaxcp.x11.protocol.Utilities.toList; @@ -96,20 +97,30 @@ public XAuthority(@NonNull Family family, @NonNull List address, int displ public static Optional read(DataInput in) { try { Family family = Family.getByCode(in.readUnsignedShort()); - int dataLength = in.readUnsignedShort(); - List address = readBytes(in, dataLength); - int number = Integer.parseInt(in.readUTF()); - dataLength = in.readUnsignedShort(); - List name = readBytes(in, dataLength); - dataLength = in.readUnsignedShort(); - List data = readBytes(in, dataLength); + int length = in.readUnsignedShort(); + List address = readBytesList(in, length); + length = in.readUnsignedShort(); + int number = 0; + if (length != 0) { + number = Integer.parseInt(new String(readBytes(in, length))); + } + length = in.readUnsignedShort(); + List name = readBytesList(in, length); + length = in.readUnsignedShort(); + List data = readBytesList(in, length); return Optional.of(new XAuthority(family, address, number, name, data)); } catch (IOException ex) { return Optional.empty(); } } - private static List readBytes(DataInput in, int length) throws IOException { + private static byte[] readBytes(DataInput in, int length) throws IOException { + byte[] bytes = new byte[length]; + in.readFully(bytes); + return bytes; + } + + private static List readBytesList(DataInput in, int length) throws IOException { byte[] bytes = new byte[length]; in.readFully(bytes); return toList(bytes);