[or-cvs] [metrics-db/master] Add checks to relay descriptor parsing.
karsten at torproject.org
karsten at torproject.org
Sun Nov 21 12:47:32 UTC 2010
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Sun, 21 Nov 2010 13:46:29 +0100
Subject: Add checks to relay descriptor parsing.
Commit: 7b0b45c7181c30c6c2c91db1179d507945af3e4f
---
.../torproject/ernie/db/RelayDescriptorParser.java | 39 ++++++++++++++------
1 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/org/torproject/ernie/db/RelayDescriptorParser.java b/src/org/torproject/ernie/db/RelayDescriptorParser.java
index c110bb5..40e3b56 100644
--- a/src/org/torproject/ernie/db/RelayDescriptorParser.java
+++ b/src/org/torproject/ernie/db/RelayDescriptorParser.java
@@ -147,6 +147,11 @@ public class RelayDescriptorParser {
}
rawStatusEntry = new StringBuilder(line + "\n");
String[] parts = line.split(" ");
+ if (parts.length < 9) {
+ this.logger.log(Level.WARNING, "Could not parse r line '"
+ + line + "' in descriptor. Skipping.");
+ break;
+ }
String publishedTime = parts[4] + " " + parts[5];
nickname = parts[1];
relayIdentity = Hex.encodeHexString(
@@ -357,6 +362,9 @@ public class RelayDescriptorParser {
intervalEnd -= intervalLength * 1000L;
}
} catch (NumberFormatException e) {
+ this.logger.log(Level.WARNING, "Could not parse "
+ + line.split(" ")[0] + " line '" + line + "' in "
+ + "descriptor. Skipping.", e);
break;
}
}
@@ -364,19 +372,26 @@ public class RelayDescriptorParser {
date = line.split(" ")[1];
} else if (line.startsWith("dirreq-v3-reqs ")
&& line.length() > "dirreq-v3-reqs ".length()) {
- int allUsers = 0;
- Map<String, String> obs = new HashMap<String, String>();
- String[] parts = line.substring("dirreq-v3-reqs ".length()).
- split(",");
- for (String p : parts) {
- String country = p.substring(0, 2);
- int users = Integer.parseInt(p.substring(3)) - 4;
- allUsers += users;
- obs.put(country, "" + users);
- }
- obs.put("zy", "" + allUsers);
if (this.dsfh != null) {
- this.dsfh.addObs(dir, date, obs);
+ try {
+ int allUsers = 0;
+ Map<String, String> obs = new HashMap<String, String>();
+ String[] parts = line.substring("dirreq-v3-reqs ".
+ length()).split(",");
+ for (String p : parts) {
+ String country = p.substring(0, 2);
+ int users = Integer.parseInt(p.substring(3)) - 4;
+ allUsers += users;
+ obs.put(country, "" + users);
+ }
+ obs.put("zy", "" + allUsers);
+ this.dsfh.addObs(dir, date, obs);
+ } catch (NumberFormatException e) {
+ this.logger.log(Level.WARNING, "Could not parse "
+ + "dirreq-v3-reqs line '" + line + "' in descriptor. "
+ + "Skipping.", e);
+ break;
+ }
}
}
}
--
1.7.1
More information about the tor-commits
mailing list