protection against strange answers from remote peers during search

pull/1/head
Michael Peter Christen 13 years ago
parent 9c51db4243
commit c639248c23

@ -666,6 +666,8 @@ public final class FileUtils
} }
public static Map<String, String> table(final byte[] a) { public static Map<String, String> table(final byte[] a) {
if (a == null) return new ConcurrentHashMap<String, String>();
//System.out.println("***TABLE: a.size = " + a.length);
return table(strings(a)); return table(strings(a));
} }
@ -674,9 +676,7 @@ public final class FileUtils
return new ArrayList<String>().iterator(); return new ArrayList<String>().iterator();
} }
try { try {
return new StringsIterator(new BufferedReader(new InputStreamReader( return new StringsIterator(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(a), "UTF-8")));
new ByteArrayInputStream(a),
"UTF-8")));
} catch ( final UnsupportedEncodingException e ) { } catch ( final UnsupportedEncodingException e ) {
return null; return null;
} }
@ -887,7 +887,7 @@ public final class FileUtils
public static class StringsIterator implements Iterator<String> public static class StringsIterator implements Iterator<String>
{ {
private final BufferedReader reader; private BufferedReader reader;
private String nextLine; private String nextLine;
public StringsIterator(final BufferedReader reader) { public StringsIterator(final BufferedReader reader) {
@ -904,7 +904,7 @@ public final class FileUtils
@Override @Override
public String next() { public String next() {
final String line = this.nextLine; final String line = this.nextLine;
try { if (this.reader != null) try {
while ( (this.nextLine = this.reader.readLine()) != null ) { while ( (this.nextLine = this.reader.readLine()) != null ) {
this.nextLine = this.nextLine.trim(); this.nextLine = this.nextLine.trim();
if ( this.nextLine.length() > 0 ) { if ( this.nextLine.length() > 0 ) {
@ -917,6 +917,13 @@ public final class FileUtils
Log.logException(e); Log.logException(e);
this.nextLine = null; this.nextLine = null;
} }
if (this.nextLine == null && this.reader != null) {
try {
this.reader.close();
} catch (IOException e) {} finally {
this.reader = null;
}
}
return line; return line;
} }

@ -956,10 +956,12 @@ public final class Protocol
} }
final HTTPClient httpClient = new HTTPClient(ClientIdentification.getUserAgent(), 8000); final HTTPClient httpClient = new HTTPClient(ClientIdentification.getUserAgent(), 8000);
resultMap = byte[] a = httpClient.POSTbytes(new MultiProtocolURI("http://" + hostaddress + "/yacy/search.html"), hostname, parts, false);
FileUtils.table(httpClient.POSTbytes(new MultiProtocolURI("http://" if (a != null && a.length > 200000) {
+ hostaddress // there is something wrong. This is too large, maybe a hack on the other side?
+ "/yacy/search.html"), hostname, parts, false)); a = null;
}
resultMap = FileUtils.table(a);
// evaluate request result // evaluate request result
if ( resultMap == null || resultMap.isEmpty() ) { if ( resultMap == null || resultMap.isEmpty() ) {

Loading…
Cancel
Save