aboutsummaryrefslogtreecommitdiff
path: root/src/or/consdiff.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-01-16 12:42:40 -0500
committerNick Mathewson <nickm@torproject.org>2018-01-16 12:42:40 -0500
commit4bb831e0873e7e4468a44dbf9e253bcd5df18421 (patch)
treecbbaed743e01779d341f6ced564ddccb462d0a3d /src/or/consdiff.c
parente3ab27001f81dc05eb1dd1ac8371a35ccce2b50d (diff)
downloadtor-4bb831e0873e7e4468a44dbf9e253bcd5df18421.tar.gz
tor-4bb831e0873e7e4468a44dbf9e253bcd5df18421.zip
Improve fragile-hardening performance of consensus_split_lines.
For whatever reason, in my testing, using memchr() here improves performance over strchr() by a great deal. Fixes bug 24826; bugfix on 0.3.1.1-alpha.
Diffstat (limited to 'src/or/consdiff.c')
-rw-r--r--src/or/consdiff.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/or/consdiff.c b/src/or/consdiff.c
index 1baa11897c..deaf465fe7 100644
--- a/src/or/consdiff.c
+++ b/src/or/consdiff.c
@@ -1285,8 +1285,11 @@ consdiff_apply_diff(const smartlist_t *cons1,
STATIC int
consensus_split_lines(smartlist_t *out, const char *s, memarea_t *area)
{
+ const char *end_of_str = s + strlen(s);
+ tor_assert(*end_of_str == '\0');
+
while (*s) {
- const char *eol = strchr(s, '\n');
+ const char *eol = memchr(s, '\n', end_of_str - s);
if (!eol) {
/* File doesn't end with newline. */
return -1;