Skip to content

Commit

Permalink
fix for 0 length txt parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
darmbrust committed Apr 22, 2020
1 parent 08d9b9f commit 9a999d4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/java/net/straylightlabs/hola/dns/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ private static String readLabel(ByteBuffer buffer, int length) {

public static List<String> readStringsFromBuffer(ByteBuffer buffer, int length) {
List<String> strings = new ArrayList<>();
int bytesRead = 0;
do {
int stringLength = buffer.get() & 0xFF;
String label = readLabel(buffer, stringLength);
bytesRead += label.length() + 1;
strings.add(label);
} while (bytesRead < length);
if (length > 0) {
int bytesRead = 0;
do {
int stringLength = buffer.get() & 0xFF;
String label = readLabel(buffer, stringLength);
bytesRead += label.length() + 1;
strings.add(label);
} while (bytesRead < length);
}
return strings;
}

Expand Down

0 comments on commit 9a999d4

Please sign in to comment.