Skip to content

Commit

Permalink
Issue #214: Handle DATA commands without actual data
Browse files Browse the repository at this point in the history
  • Loading branch information
hypfvieh committed Jun 2, 2023
1 parent 3cf266b commit 58e2e49
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package org.freedesktop.dbus.connections;

import static org.freedesktop.dbus.connections.SASL.SaslCommand.AGREE_UNIX_FD;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.AUTH;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.BEGIN;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.CANCEL;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.DATA;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.ERROR;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.NEGOTIATE_UNIX_FD;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.REJECTED;
import static org.freedesktop.dbus.connections.SASL.SaslCommand.*;

import com.sun.security.auth.module.UnixSystem;
import org.freedesktop.dbus.config.DBusSysProps;
Expand All @@ -17,37 +10,22 @@
import org.freedesktop.dbus.exceptions.AuthenticationException;
import org.freedesktop.dbus.exceptions.SocketClosedException;
import org.freedesktop.dbus.messages.Message;
import org.freedesktop.dbus.utils.Hexdump;
import org.freedesktop.dbus.utils.LoggingHelper;
import org.freedesktop.dbus.utils.TimeMeasure;
import org.freedesktop.dbus.utils.Util;
import org.freedesktop.dbus.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.NetworkChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.*;
import java.nio.file.attribute.PosixFilePermission;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.*;

public class SASL {
public static final int AUTH_NONE = 0;
Expand Down Expand Up @@ -863,7 +841,8 @@ public Command(String _s) throws IOException {
}
} else if (0 == COL.compare(ss[0], "DATA")) {
command = DATA;
data = ss[1];
// ss[1] might be non-existing or empty (e.g. AUTH ANON)
data = ss.length < 2 ? null : ss[1];
} else if (0 == COL.compare(ss[0], "REJECTED")) {
command = REJECTED;
for (int i = 1; i < ss.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.freedesktop.dbus.connections;

import org.freedesktop.dbus.connections.SASL.Command;
import org.freedesktop.dbus.connections.SASL.SaslCommand;
import org.freedesktop.dbus.test.AbstractBaseTest;
import org.junit.jupiter.api.Test;

import java.io.IOException;

public class SASLTest extends AbstractBaseTest {

@Test
public void testCommandNoData() throws IOException {
Command cmdData = new Command("DATA ");
assertEquals(SaslCommand.DATA, cmdData.getCommand());
assertNull(cmdData.getData());
}

@Test
public void testCommandWithData() throws IOException {
Command cmdData = new Command("DATA blafasel");
assertEquals(SaslCommand.DATA, cmdData.getCommand());
assertEquals("blafasel", cmdData.getData());
}

@Test
public void testCommandAuth() throws IOException {
Command cmdData = new Command("AUTH ");
assertEquals(SaslCommand.AUTH, cmdData.getCommand());
assertNull(cmdData.getData());
}

}

0 comments on commit 58e2e49

Please sign in to comment.