Skip to content

Commit fa3f672

Browse files
committed
make cache thread safe.
changed names a while.
1 parent b986abe commit fa3f672

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

cSploit/src/org/csploit/android/net/http/RequestParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public static String getBaseDomain(String hostname){
297297
if(Patterns.IP_ADDRESS.matcher(hostname).matches())
298298
return hostname;
299299

300-
String cached_domain = DNSCache.getInstance().getCachedRootDomain(hostname);
300+
String cached_domain = DNSCache.getInstance().getRootDomain(hostname);
301301
if (cached_domain != null) {
302302
return cached_domain;
303303
}
@@ -318,7 +318,7 @@ public static String getBaseDomain(String hostname){
318318
domain += host_parts[i] + ".";
319319
}
320320

321-
DNSCache.getInstance().addCachedRootDomain(domain.substring(0, domain.length() - 1));
321+
DNSCache.getInstance().addRootDomain(domain.substring(0, domain.length() - 1));
322322
return domain.substring(0, domain.length() - 1);
323323
}
324324
}
@@ -333,7 +333,7 @@ public static String getBaseDomain(String hostname){
333333
}
334334

335335
if(startIndex > 0) {
336-
DNSCache.getInstance().addCachedRootDomain(hostname.substring(startIndex));
336+
DNSCache.getInstance().addRootDomain(hostname.substring(startIndex));
337337
return hostname.substring(startIndex);
338338
}
339339
else

cSploit/src/org/csploit/android/net/http/proxy/DNSCache.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ public class DNSCache
3232
{
3333
private static DNSCache mInstance = new DNSCache();
3434

35-
private HashMap<String, InetAddress> mCache = null;
36-
private ArrayList<String> mCachedRootDomain = null;
35+
private final HashMap<String, InetAddress> mCache;
36+
private final ArrayList<String> mRootDomainCache;
3737

3838
public static DNSCache getInstance(){
3939
return mInstance;
4040
}
4141

4242
private DNSCache() {
4343
mCache = new HashMap<>();
44-
mCachedRootDomain = new ArrayList<>();
44+
mRootDomainCache = new ArrayList<>();
4545
}
4646

4747
/**
@@ -50,10 +50,12 @@ private DNSCache() {
5050
* @param hostname hostname to check
5151
* @return String the root domain or null
5252
*/
53-
public String getCachedRootDomain (String hostname){
54-
for (String rootDomain : mCachedRootDomain){
55-
if (hostname.endsWith(rootDomain)){
56-
return rootDomain;
53+
public String getRootDomain(String hostname){
54+
synchronized (mRootDomainCache) {
55+
for (String rootDomain : mRootDomainCache) {
56+
if (hostname.endsWith(rootDomain)) {
57+
return rootDomain;
58+
}
5759
}
5860
}
5961

@@ -66,8 +68,10 @@ public String getCachedRootDomain (String hostname){
6668
*
6769
* @param rootdomain Root domain to add to the list
6870
*/
69-
public void addCachedRootDomain (String rootdomain){
70-
mCachedRootDomain.add(rootdomain);
71+
public void addRootDomain(String rootdomain){
72+
synchronized (mRootDomainCache) {
73+
mRootDomainCache.add(rootdomain);
74+
}
7175
}
7276

7377
private InetAddress getAddress(String server) throws IOException{

0 commit comments

Comments
 (0)