Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Strip IP address from IP address / domain name pair for better wildcards
Browse files Browse the repository at this point in the history
Fixes #2014
  • Loading branch information
M66B committed Oct 4, 2014
1 parent 91fad02 commit 92e4805
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ See for more information about XPrivacy 3 [this FAQ](https://github.com/M66B/XPr

**Next release**

* Strip IP address from IP address / domain name pair for better wildcards ([issue](/../../issues/2014))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

**Version 3.3.3 BETA**
Expand Down
20 changes: 13 additions & 7 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ else if (hook.getFrom() != null) {
}
}

// Process IP address
if (restriction.extra != null && Meta.cTypeIPAddress.equals(hook.whitelist())) {
int colon = restriction.extra.lastIndexOf(':');
String address = (colon >= 0 ? restriction.extra.substring(0, colon) : restriction.extra);
String port = (colon >= 0 ? restriction.extra.substring(colon) : "");

int slash = address.indexOf('/');
if (slash == 0) // IP address
restriction.extra = address.substring(slash + 1) + port;
else if (slash > 0) // Domain name
restriction.extra = address.substring(0, slash) + port;
}

// Check for system component
if (!PrivacyManager.isApplication(restriction.uid))
if (!getSettingBool(userId, PrivacyManager.cSettingSystem, false))
Expand Down Expand Up @@ -1976,13 +1989,6 @@ private String[] getXExtra(PRestriction restriction, Hook hook) {
// sub-domain or sub-net
int colon = restriction.extra.lastIndexOf(':');
String address = (colon >= 0 ? restriction.extra.substring(0, colon) : restriction.extra);

int slash = address.indexOf('/');
if (slash == 0)
address = address.substring(slash + 1); // IP address
else if (slash > 0)
address = address.substring(0, slash); // domain name

if (Patterns.IP_ADDRESS.matcher(address).matches()) {
int dot = address.lastIndexOf('.');
listResult.add(address.substring(0, dot) + ".*"
Expand Down

0 comments on commit 92e4805

Please sign in to comment.