Skip to content

Commit

Permalink
Fixed xauth parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
moaxcp committed Dec 26, 2024
1 parent b12d18e commit 0a20098
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The x11-client library can be added to your project using maven or gradle.
<dependency>
<groupId>com.github.moaxcp.x11</groupId>
<artifactId>x11-client</artifactId>
<version>0.18.2</version>
<version>0.20.0</version>
<type>module</type>
</dependency>
```
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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;
import java.nio.charset.StandardCharsets;
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;
Expand Down Expand Up @@ -96,20 +97,30 @@ public XAuthority(@NonNull Family family, @NonNull List<Byte> address, int displ
public static Optional<XAuthority> read(DataInput in) {
try {
Family family = Family.getByCode(in.readUnsignedShort());
int dataLength = in.readUnsignedShort();
List<Byte> address = readBytes(in, dataLength);
int number = Integer.parseInt(in.readUTF());
dataLength = in.readUnsignedShort();
List<Byte> name = readBytes(in, dataLength);
dataLength = in.readUnsignedShort();
List<Byte> data = readBytes(in, dataLength);
int length = in.readUnsignedShort();
List<Byte> 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<Byte> name = readBytesList(in, length);
length = in.readUnsignedShort();
List<Byte> data = readBytesList(in, length);
return Optional.of(new XAuthority(family, address, number, name, data));
} catch (IOException ex) {
return Optional.empty();
}
}

private static List<Byte> 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<Byte> readBytesList(DataInput in, int length) throws IOException {
byte[] bytes = new byte[length];
in.readFully(bytes);
return toList(bytes);
Expand Down

0 comments on commit 0a20098

Please sign in to comment.