Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def packageTask(String platform, Closure doMore) {
'Title': 'Angry IP Scanner',
'Version': version,
'Build-Date': java.time.LocalDate.now().toString(),
'URL': 'https://angryip.org/'
'URL': 'https://angryip.org/',
'Add-Opens': 'java.base/java.net'

if (platform != "any") {
def swtJar = configurations[platform].files.find { file ->
Expand Down Expand Up @@ -242,7 +243,9 @@ def rpm(def platform, def arch) {
ant.replacefilter(token: "VERSION", value: version)
}
exec(new String[] {"sh", "-c", "rpmbuild --target ${arch} --define \"_topdir ${new File(dist).absolutePath}\" --define \"platform ${platform}\" -bb SPECS/ipscan.spec"}, dist)
ant.move(file: "${dist}/RPMS/${arch}/ipscan-${rpmVersion}-1.${arch}.rpm", todir:'build/libs')
ant.move(todir: 'build/libs') {
ant.fileset(dir: "${dist}/RPMS/${arch}", includes: "ipscan-${rpmVersion}-1.*${arch}.rpm")
}
ant.delete(dir: dist)
}

Expand Down
25 changes: 24 additions & 1 deletion src/net/azib/ipscan/fetchers/HostnameFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.logging.Logger;

import static java.util.logging.Level.FINE;
Expand Down Expand Up @@ -78,7 +80,28 @@ private String resolveWithRegularDNS(InetAddress ip) {
return null;
}
}
return hostname;
return unescapeDNSName(hostname);
}

private static final Pattern DNS_ESCAPE_PATTERN = Pattern.compile("\\\\(\\d{3})");

/**
* Some routers/DNS servers incorrectly send raw zone-file escape sequences
* (RFC 1035 presentation format, e.g. "\032" for a space) as literal bytes
* in PTR records, instead of the actual characters they represent.
* This decodes such "\DDD" decimal escape sequences back into their original characters.
*/
static String unescapeDNSName(String hostname) {
if (hostname == null || hostname.indexOf('\\') < 0) return hostname;
var matcher = DNS_ESCAPE_PATTERN.matcher(hostname);
var result = new StringBuilder();
while (matcher.find()) {
int code = Integer.parseInt(matcher.group(1));
var replacement = code <= 255 ? String.valueOf((char) code) : matcher.group();
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
}
matcher.appendTail(result);
return result.toString();
}

private String resolveWithMulticastDNS(ScanningSubject subject) {
Expand Down
2 changes: 1 addition & 1 deletion src/net/azib/ipscan/gui/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private void createPortsTab() {
label = new Label(portsGroup, SWT.WRAP);
label.setText(Labels.getLabel("preferences.ports.portsDescription"));
//label.setLayoutData(new RowData(300, SWT.DEFAULT));
portsText = new Text(portsGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
portsText = new Text(portsGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP);
portsText.setLayoutData(new RowData(SWT.DEFAULT, 60));
portsText.addKeyListener(new PortsTextValidationListener());

Expand Down
6 changes: 6 additions & 0 deletions src/net/azib/ipscan/gui/actions/OpenerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ static String[] splitCommand(String command) {
var token = tokenizer.nextToken(" \t");

try {
// a token fully wrapped in matching quotes with no embedded whitespace
// (e.g. a value substituted by an opener, such as 'x' or "x") - unwrap directly
if (token.length() > 1 && ((token.startsWith("\"") && token.endsWith("\"")) || (token.startsWith("'") && token.endsWith("'")))) {
token = token.substring(1, token.length() - 1);
}
else
if (token.startsWith("\"")) {
token = token.substring(1) + tokenizer.nextToken("\"");
tokenizer.nextToken(" \t");
Expand Down
8 changes: 8 additions & 0 deletions test/net/azib/ipscan/fetchers/HostnameFetcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ public void resolveForReal() throws UnknownHostException {
if (inexistentAddress.getHostName().equals("192.168.253.253"))
assertNull(fetcher.scan(new ScanningSubject(inexistentAddress)));
}

@Test
public void unescapesDNSEscapeSequences() {
assertEquals(" guest wan", HostnameFetcher.unescapeDNSName("\\032guest\\032wan"));
assertEquals("my-router", HostnameFetcher.unescapeDNSName("my-router"));
assertNull(HostnameFetcher.unescapeDNSName(null));
assertEquals("\\999invalid", HostnameFetcher.unescapeDNSName("\\999invalid"));
}
}
3 changes: 3 additions & 0 deletions test/net/azib/ipscan/gui/actions/OpenerLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public void testCommandSplitting() throws Exception {
assertArrayEquals(new String[] {"echo", "hello world", "muha-ha"}, OpenerLauncher.splitCommand("echo \"hello world\" muha-ha"));
assertArrayEquals(new String[] {"mix \"1", "mix '2"}, OpenerLauncher.splitCommand("'mix \"1' \"mix '2\""));
assertArrayEquals(new String[] {"\"aaa"}, OpenerLauncher.splitCommand("\"aaa"));
// single quoted value with no embedded whitespace (as produced by sanitizeForShell) must be fully unquoted
assertArrayEquals(new String[] {"notepad", "192.168.1.1"}, OpenerLauncher.splitCommand("notepad '192.168.1.1'"));
assertArrayEquals(new String[] {"notepad", "192.168.1.1"}, OpenerLauncher.splitCommand("notepad \"192.168.1.1\""));
}

private Feeder mockFeeder(String feederInfo) {
Expand Down