Skip to content

Commit

Permalink
protection against too large seeds
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3877 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jun 12, 2007
1 parent 684ded0 commit 4f54960
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions htroot/yacy/hello.java
Expand Up @@ -79,6 +79,10 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
int count = 0;
try {count = (countStr == null) ? 0 : Integer.parseInt(countStr);} catch (NumberFormatException e) {count = 0;}
// final Date remoteTime = yacyCore.parseUniversalDate((String) post.get(MYTIME)); // read remote time
if (seed.length() > yacySeed.maxsize) {
yacyCore.log.logInfo("hello/server: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");
return null;
}
final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key, false);

// System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString()));
Expand Down
21 changes: 15 additions & 6 deletions source/de/anomic/yacy/yacyClient.java
Expand Up @@ -157,12 +157,17 @@ public static int publishMySeed(String address, String otherHash) {
yacySeed otherPeer = null;
float otherPeerVersion = 0;
if (otherHash != null && otherHash.length() > 0) {
otherPeer = yacySeed.genRemoteSeed((String) result.get("seed0"), key, true);
if (otherPeer == null || !otherPeer.hash.equals(otherHash)) {
yacyCore.log.logFine("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");
return -1; // no success
String seed = (String) result.get("seed0");
if (seed.length() > yacySeed.maxsize) {
yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");
} else {
otherPeer = yacySeed.genRemoteSeed(seed, key, true);
if (otherPeer == null || !otherPeer.hash.equals(otherHash)) {
yacyCore.log.logFine("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");
return -1; // no success
}
otherPeerVersion = otherPeer.getVersion();
}
otherPeerVersion = otherPeer.getVersion();
}

// set my own seed according to new information
Expand Down Expand Up @@ -239,7 +244,11 @@ public static int publishMySeed(String address, String otherHash) {
while ((seedStr = (String) result.get("seed" + i++)) != null) {
// integrate new seed into own database
// the first seed, "seed0" is the seed of the responding peer
if (yacyCore.peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, key, true), (i == 1))) count++;
if (seedStr.length() > yacySeed.maxsize) {
yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")");
} else {
if (yacyCore.peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, key, true), (i == 1))) count++;
}
}
return count;
}
Expand Down
1 change: 1 addition & 0 deletions source/de/anomic/yacy/yacySeed.java
Expand Up @@ -85,6 +85,7 @@

public class yacySeed {

public static final int maxsize = 2048;
/**
* <b>substance</b> "sI" (send index/words)
*/
Expand Down

0 comments on commit 4f54960

Please sign in to comment.