aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-07-16 18:26:31 +0000
committerNick Mathewson <nickm@torproject.org>2007-07-16 18:26:31 +0000
commitad45ddfb0754ae52bc372fd4fd4867b140765ef5 (patch)
tree2d3894b1d574809f1115a682ae08f82171b77692 /src/common/util.c
parent6e9f1f76f21306d8c4d66af990f11e78f6dc234d (diff)
downloadtor-ad45ddfb0754ae52bc372fd4fd4867b140765ef5.tar.gz
tor-ad45ddfb0754ae52bc372fd4fd4867b140765ef5.zip
r13788@catbus: nickm | 2007-07-16 14:26:25 -0400
Patch from croup: rewrite the logic of get_next_token() to do the right thing with input that ends at weird places, or aligns with block boundaries after mmap. should fix bug 455. Needs fuzzing. svn:r10847
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/common/util.c b/src/common/util.c
index cfc06d4208..10c3cb8476 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -403,6 +403,21 @@ strcmpstart(const char *s1, const char *s2)
return strncmp(s1, s2, n);
}
+/** Compare the s1_len-byte string <b>s1</b> with <b>s2</b>,
+ * without depending on a terminating nul in s1. Sorting order is first by
+ * length, then lexically; return values are as for strcmp.
+ */
+int
+strcmp_len(const char *s1, const char *s2, size_t s1_len)
+{
+ size_t s2_len = strlen(s2);
+ if (s1_len < s2_len)
+ return -1;
+ if (s1_len > s2_len)
+ return 1;
+ return memcmp(s1, s2, s2_len);
+}
+
/** Compares the first strlen(s2) characters of s1 with s2. Returns as for
* strcasecmp.
*/
@@ -505,7 +520,8 @@ eat_whitespace_no_nl(const char *s)
return s;
}
-/** DOCDOC */
+/** As eat_whitespace_no_nl, but stop at <b>eos</b> whether we have
+ * found a non-whitespace character or not. */
const char *
eat_whitespace_eos_no_nl(const char *s, const char *eos)
{
@@ -537,7 +553,8 @@ find_whitespace(const char *s)
}
}
-/** DOCDOC */
+/** As find_whitespace, but stop at <b>eos</b> whether we have found a
+ * whitespace or not. */
const char *
find_whitespace_eos(const char *s, const char *eos)
{
@@ -556,10 +573,9 @@ find_whitespace_eos(const char *s, const char *eos)
++s;
}
}
- return NULL;
+ return s;
}
-
/** Return true iff the 'len' bytes at 'mem' are all zero. */
int
tor_mem_is_zero(const char *mem, size_t len)