Skip to content

Commit

Permalink
Fix NumberFormatException in LinuxEphemeralPortRangeDetector
Browse files Browse the repository at this point in the history
Fix NumberFormatException in LinuxEphemeralPortRangeDetector when the
ephemeral port file contains multiple whispaces.

Fixes #7354

Signed-off-by: Alexei Barantsev <[email protected]>
  • Loading branch information
nsotgui authored and barancev committed Jul 18, 2019
1 parent df8eed8 commit f2518bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static LinuxEphemeralPortRangeDetector getInstance() {
int lowPort = defaultRange.getLowestEphemeralPort();
int highPort = defaultRange.getHighestEphemeralPort();
try (BufferedReader in = new BufferedReader(inputFil)) {
String[] split = in.readLine().split("\\s");
String[] split = in.readLine().split("\\s+");
lowPort = Integer.parseInt(split[0]);
highPort = Integer.parseInt(split[1]);
} catch (IOException ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public void decodeEphemeralPorts() {
assertThat(ephemeralEphemeralPortDetector.getHighestEphemeralPort()).isEqualTo(65533);
}

@Test
public void decodeEphemeralPortsWithWhitespaces() {
String range ="1234 65533";
EphemeralPortRangeDetector ephemeralEphemeralPortDetector =
new LinuxEphemeralPortRangeDetector(new StringReader(range));
assertThat(ephemeralEphemeralPortDetector.getLowestEphemeralPort()).isEqualTo(1234);
assertThat(ephemeralEphemeralPortDetector.getHighestEphemeralPort()).isEqualTo(65533);
}

@Test
public void currentValues() {
LinuxEphemeralPortRangeDetector detector = LinuxEphemeralPortRangeDetector.getInstance();
Expand Down

0 comments on commit f2518bf

Please sign in to comment.