[tor-commits] [metrics-lib/master] Accept [SP|TAB]+ as delimiter in two places.
karsten at torproject.org
karsten at torproject.org
Mon Jun 16 07:09:26 UTC 2014
commit 2351cead7a693c53f3ec8329e84ca15add55c945
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Mon Jun 16 07:32:55 2014 +0200
Accept [SP|TAB]+ as delimiter in two places.
There have been at least two relays including an additional SP after their
nickname in server and extra-info descriptors. The spec stays vague about
whether this is allowed or not, but the directory authorities seem to
accept these descriptors just fine. We should also accept these
descriptors.
We should probably accept [SP|TAB]+ in more places. But right now we're
losing data by discarding these descriptors. Let's do the quick fix now
and the potentially cleaner fix later.
Fixes #12403.
---
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 13 +++++++++++--
.../torproject/descriptor/impl/ServerDescriptorImpl.java | 13 +++++++++++--
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index a533113..5951da0 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -201,8 +201,17 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
private void parseExtraInfoLine(String line, String lineNoOpt,
String[] partsNoOpt) throws DescriptorParseException {
if (partsNoOpt.length != 3) {
- throw new DescriptorParseException("Illegal line '" + line
- + "' in extra-info descriptor.");
+ /* Also accept [SP|TAB]+ where we'd previously only accept SP as
+ * delimiter. This is a hotfix for #12403, because we're currently
+ * not storing valid descriptors. A better place to implement this
+ * would probably be in DescriptorImpl. */
+ partsNoOpt = line.startsWith("opt ") ?
+ line.substring("opt ".length()).split("[ \t]+") :
+ line.split("[ \t]+");
+ if (partsNoOpt.length != 3) {
+ throw new DescriptorParseException("Illegal line '" + line
+ + "' in extra-info descriptor.");
+ }
}
this.nickname = ParseHelper.parseNickname(line, partsNoOpt[1]);
this.fingerprint = ParseHelper.parseTwentyByteHexString(line,
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 52d49b0..69ffcd8 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -170,8 +170,17 @@ public class ServerDescriptorImpl extends DescriptorImpl
private void parseRouterLine(String line, String lineNoOpt,
String[] partsNoOpt) throws DescriptorParseException {
if (partsNoOpt.length != 6) {
- throw new DescriptorParseException("Illegal line '" + line
- + "' in server descriptor.");
+ /* Also accept [SP|TAB]+ where we'd previously only accept SP as
+ * delimiter. This is a hotfix for #12403, because we're currently
+ * not storing valid descriptors. A better place to implement this
+ * would probably be in DescriptorImpl. */
+ partsNoOpt = line.startsWith("opt ") ?
+ line.substring("opt ".length()).split("[ \t]+") :
+ line.split("[ \t]+");
+ if (partsNoOpt.length != 6) {
+ throw new DescriptorParseException("Illegal line '" + line
+ + "' in server descriptor.");
+ }
}
this.nickname = ParseHelper.parseNickname(line, partsNoOpt[1]);
this.address = ParseHelper.parseIpv4Address(line, partsNoOpt[2]);
More information about the tor-commits
mailing list