fix to prevent bad-formed news messages

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3960 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent bec4dbc753
commit a45216b479

@ -188,7 +188,7 @@ public class Blog {
map.put("page", pagename);
map.put("subject", StrSubject.replace(',', ' '));
map.put("author", StrAuthor.replace(',', ' '));
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_BLOG_ADD, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_BLOG_ADD, map));
}
page = switchboard.blogDB.read(pagename); //maybe "if(page == null)"

@ -322,7 +322,7 @@ public class Bookmarks {
map.put("title", title.replace(',', ' '));
map.put("description", description.replace(',', ' '));
map.put("tags", tagsString.replace(',', ' '));
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
}
}

@ -113,7 +113,7 @@ public class ConfigProfile_p {
// generate a news message
Properties news = profile;
news.remove("comment");
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_PROFILE_UPDATE, news));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_PROFILE_UPDATE, news));
//yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsRecord.CATEGORY_PROFILE_UPDATE, profile));
} catch(IOException e) {
} finally {

@ -78,7 +78,7 @@ public class Supporter {
map.put("urlhash", hash);
map.put("vote", "negative");
map.put("refid", post.get("refid", ""));
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
if ((post != null) && ((hash = post.get("votePositive", null)) != null)) {
if (!sb.verifyAuthentication(header, false)) {

@ -86,7 +86,7 @@ public class Surftips {
map.put("urlhash", hash);
map.put("vote", "negative");
map.put("refid", post.get("refid", ""));
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
if ((post != null) && ((hash = post.get("votePositive", null)) != null)) {
if (!sb.verifyAuthentication(header, false)) {

@ -210,7 +210,7 @@ public class WatchCrawler_p {
m.remove("generalFilter");
m.remove("specificFilter");
m.put("intention", post.get("intention", "").replace(',', '/'));
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_CRAWL_START, m));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_CRAWL_START, m));
}
} else {

@ -136,7 +136,7 @@ public class Wiki {
map.put("page", pagename);
map.put("author", author.replace(',', ' '));
if (post.get("content", "").trim().length() > 0 && !page.page().equals(content))
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_WIKI_UPDATE, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_WIKI_UPDATE, map));
page = newEntry;
prop.put("LOCATION", "/Wiki.html?page=" + pagename);
}

@ -232,7 +232,7 @@ public class yacysearch {
map.put("urlhash", delHash);
map.put("vote", "negative");
map.put("refid", "");
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
// if aplus-button was hit, create new voting message

@ -2053,7 +2053,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
if ((homepage != null) && (homepage.length() > 10)) {
Properties news = new Properties();
news.put("homepage", profile.get("homepage"));
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_PROFILE_BROADCAST, news));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_PROFILE_BROADCAST, news));
}
}

@ -760,7 +760,7 @@ public class AdminService extends AbstractService {
// generate a news message
Properties news = profile;
news.remove(PEERPROFILE_COMMENT);
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_PROFILE_UPDATE, news));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_PROFILE_UPDATE, news));
} catch(IOException e) {
throw new AxisFault("Unable to write profile data to file");
} finally {

@ -184,7 +184,7 @@ public class BookmarkService extends AbstractService {
map.put("title", title.replace(',', ' '));
map.put("description", description.replace(',', ' '));
map.put("tags", tagString);
yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
}
/**

@ -62,18 +62,20 @@ public class yacyNewsAction implements yacyPeerAction {
//System.out.println("### triggered news arrival from peer " + peer.getName() + ", news " + ((recordString == null) ? "empty" : "attached"));
if ((recordString == null) || (recordString.length() == 0)) return;
String decodedString = de.anomic.tools.crypt.simpleDecode(recordString, "");
yacyNewsRecord record = new yacyNewsRecord(decodedString);
//System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString());
String cre1 = (String) serverCodings.string2map(decodedString, ",").get("cre");
String cre2 = (String) serverCodings.string2map(record.toString(), ",").get("cre");
if ((cre1 == null) || (cre2 == null) || (!(cre1.equals(cre2)))) {
System.out.println("### ERROR - cre are not equal: cre1=" + cre1 + ", cre2=" + cre2);
return;
}
try {
synchronized (pool) {this.pool.enqueueIncomingNews(record);}
} catch (IOException e) {
serverLog.logSevere("YACY", "processPeerArrival", e);
yacyNewsRecord record = yacyNewsRecord.newRecord(decodedString);
if (record != null) {
//System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString());
String cre1 = (String) serverCodings.string2map(decodedString, ",").get("cre");
String cre2 = (String) serverCodings.string2map(record.toString(), ",").get("cre");
if ((cre1 == null) || (cre2 == null) || (!(cre1.equals(cre2)))) {
System.out.println("### ERROR - cre are not equal: cre1=" + cre1 + ", cre2=" + cre2);
return;
}
try {
synchronized (pool) {this.pool.enqueueIncomingNews(record);}
} catch (IOException e) {
serverLog.logSevere("YACY", "processPeerArrival", e);
}
}
}

@ -139,7 +139,7 @@ public class yacyNewsDB {
protected final static yacyNewsRecord b2r(kelondroRow.Entry b) {
if (b == null) return null;
return new yacyNewsRecord(
return yacyNewsRecord.newRecord(
b.getColString(0, null),
b.getColString(1, "UTF-8"),
(b.empty(2)) ? null : yacyCore.parseUniversalDate(b.getColString(2, null), serverDate.UTCDiffString()),
@ -149,8 +149,8 @@ public class yacyNewsDB {
}
protected final kelondroRow.Entry r2b(yacyNewsRecord r) {
if (r == null) return null;
try {
if (r == null) return null;
String attributes = r.attributes().toString();
if (attributes.length() > yacyNewsRecord.attributesMaxLength) throw new IllegalArgumentException("attribute length=" + attributes.length() + " exceeds maximum size=" + yacyNewsRecord.attributesMaxLength);
kelondroRow.Entry entry = this.news.row().newEntry();

@ -295,6 +295,7 @@ public class yacyNewsPool {
public void publishMyNews(yacyNewsRecord record) {
// this shall be called if our peer generated a new news record and wants to publish it
if (record == null) return;
try {
if (newsDB.get(record.id()) == null) {
incomingNews.push(record); // we want to see our own news..

@ -80,19 +80,48 @@ public class yacyNewsRecord {
kelondroNaturalOrder.naturalOrder, 0
);
public static yacyNewsRecord newRecord(String newsString) {
try {
return new yacyNewsRecord(newsString);
} catch (IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public static yacyNewsRecord newRecord(String category, Map attributes) {
try {
return new yacyNewsRecord(category, attributes);
} catch (IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public static yacyNewsRecord newRecord(String id, String category, Date received, int distributed, Map attributes) {
try {
return new yacyNewsRecord(id, category, received, distributed, attributes);
} catch (IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public yacyNewsRecord(String newsString) {
this.attributes = serverCodings.string2map(newsString, ",");
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.category = (attributes.containsKey("cat")) ? (String) attributes.get("cat") : "";
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
this.received = (attributes.containsKey("rec")) ? yacyCore.parseUniversalDate((String) attributes.get("rec"), serverDate.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? yacyCore.parseUniversalDate((String) attributes.get("cre"), serverDate.UTCDiffString()) : new Date();
this.category = (attributes.containsKey("cat")) ? (String) attributes.get("cat") : "";
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt((String) attributes.get("dis")) : 0;
this.originator = (attributes.containsKey("ori")) ? (String) attributes.get("ori") : "";
removeStandards();
}
public yacyNewsRecord(String category, Map attributes) {
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length exceeds maximum");
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.attributes = attributes;
this.received = null;
this.created = new Date();
@ -100,10 +129,11 @@ public class yacyNewsRecord {
this.distributed = 0;
this.originator = yacyCore.seedDB.mySeed.hash;
removeStandards();
truncAttrLengthToMax();
}
protected yacyNewsRecord(String id, String category, Date received, int distributed, Map attributes) {
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.attributes = attributes;
this.received = received;
this.created = yacyCore.parseUniversalDate(id.substring(0, yacyCore.universalDateShortPattern.length()), serverDate.UTCDiffString());
@ -111,7 +141,6 @@ public class yacyNewsRecord {
this.distributed = distributed;
this.originator = id.substring(yacyCore.universalDateShortPattern.length());
removeStandards();
truncAttrLengthToMax();
}
private void removeStandards() {
@ -122,13 +151,6 @@ public class yacyNewsRecord {
attributes.remove("dis");
}
private void truncAttrLengthToMax() {
String s = this.attributes.toString();
if (s.length() <= attributesMaxLength) return;
this.attributes = serverCodings.string2map(
s.substring(0, s.lastIndexOf(',', attributesMaxLength)), ",");
}
public String toString() {
// this creates the string that shall be distributed
// attention: this has no additional encoding
@ -181,6 +203,6 @@ public class yacyNewsRecord {
}
public static void main(String[] args) {
System.out.println((new yacyNewsRecord(args[0])).toString());
System.out.println((newRecord(args[0])).toString());
}
}
Loading…
Cancel
Save