summaryrefslogtreecommitdiff
path: root/src/or/protover.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-08-23 14:02:48 -0400
committerNick Mathewson <nickm@torproject.org>2016-09-26 10:56:50 -0700
commita232161f7beeecebf31b2259a571e8b26cb0b541 (patch)
tree6624b80816c112523b64b2cd8a49129a4ae30dbd /src/or/protover.c
parent0697e413efa32b71d080353e5151beee117fca04 (diff)
downloadtor-a232161f7beeecebf31b2259a571e8b26cb0b541.tar.gz
tor-a232161f7beeecebf31b2259a571e8b26cb0b541.zip
Cover the error cases of parsing protocol versions
Also, detect an additional failure type. Thanks, tests! (How distinctly I recall thee)
Diffstat (limited to 'src/or/protover.c')
-rw-r--r--src/or/protover.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/or/protover.c b/src/or/protover.c
index 3a2d4014cd..2bde02c6ae 100644
--- a/src/or/protover.c
+++ b/src/or/protover.c
@@ -39,8 +39,10 @@ protocol_type_to_str(protocol_type_t pr)
if (PROTOCOL_NAMES[i].protover_type == pr)
return PROTOCOL_NAMES[i].name;
}
+ /* LCOV_EXCL_START */
tor_assert_nonfatal_unreached_once();
return "UNKNOWN";
+ /* LCOV_EXCL_STOP */
}
/**
@@ -150,6 +152,10 @@ parse_single_entry(const char *s, const char *end_of_entry)
if (!equals)
goto error;
+ /* The name must be nonempty */
+ if (equals == s)
+ goto error;
+
out->name = tor_strndup(s, equals-s);
tor_assert(equals < end_of_entry);
@@ -388,7 +394,7 @@ contract_protocol_list(const smartlist_t *proto_strings)
SMARTLIST_FOREACH_BEGIN(proto_strings, const char *, s) {
proto_entry_t *ent = parse_single_entry(s, s+strlen(s));
if (BUG(!ent))
- continue;
+ continue; // LCOV_EXCL_LINE
smartlist_t *lst = strmap_get(entry_lists_by_name, ent->name);
if (!lst) {
smartlist_add(all_names, ent->name);
@@ -591,11 +597,11 @@ protocol_list_contains(const smartlist_t *protos,
protocol_type_t pr, uint32_t ver)
{
if (BUG(protos == NULL)) {
- return 0;
+ return 0; // LCOV_EXCL_LINE
}
const char *pr_name = protocol_type_to_str(pr);
if (BUG(pr_name == NULL)) {
- return 0;
+ return 0; // LCOV_EXCL_LINE
}
SMARTLIST_FOREACH_BEGIN(protos, const proto_entry_t *, ent) {