Skip to content

Commit

Permalink
Make sure that version number resembles a valid API version
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Apr 22, 2024
1 parent b0f4e69 commit 2b36361
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions core/java/src/net/i2p/util/VersionComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,16 @@ private static long parseLong(String s, int start, int end) {
return -1;
return rv;
}

/**
* Validate an API version string.
*
* @param version
* @return true if valid
*/
public static boolean isValid(String version) {
if (version.split(".").length != 3)
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.i2p.util.ByteCache;
import net.i2p.util.Log;
import net.i2p.util.SimpleByteCache;
import net.i2p.util.VersionComparator;

/**
*
Expand Down Expand Up @@ -793,6 +794,7 @@ protected void releaseBufs(boolean isVerified) {
* get a list of caps and versions which should be soft-banned from the router.config file
*
* @since 0.5.63
* @return a map of caps and versions
*/
private HashMap<String, String> banCapsForVersion() {
HashMap caps = new HashMap<String, String>();
Expand All @@ -801,7 +803,13 @@ private HashMap<String, String> banCapsForVersion() {
String[] pairs = _context.getProperty("router.banVersionCaps", "0.9.56:LU").split(",");
for (String pair : pairs) {
String[] split = pair.split(":");
if (split.length == 2) caps.put(split[0], split[1]);
if (split.length == 2) {
String validatedVersion = split[0];
if (!VersionComparator.isValid(validatedVersion))
continue;
String validatedCaps = split[1];
caps.put(validatedVersion, validatedCaps);
}
}
return caps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,9 @@ public synchronized void queuePossibleDataPacket(UDPPacket packet) {
/**
* get a list of caps and versions which should be soft-banned from the router.config file
*
* @since 0.5.63
*
* @since 0.9.63
* @return a map of caps and versions
*/
private HashMap<String, String> banCapsForVersion() {
HashMap caps = new HashMap<String, String>();
Expand All @@ -1059,7 +1061,13 @@ private HashMap<String, String> banCapsForVersion() {
String[] pairs = _context.getProperty("router.banVersionCaps", "0.9.56:LU").split(",");
for (String pair : pairs) {
String[] split = pair.split(":");
if (split.length == 2) caps.put(split[0], split[1]);
if (split.length == 2) {
String validatedVersion = split[0];
if (!VersionComparator.isValid(validatedVersion))
continue;
String validatedCaps = split[1];
caps.put(validatedVersion, validatedCaps);
}
}
return caps;
}
Expand Down

0 comments on commit 2b36361

Please sign in to comment.