diff options
author | Craig Tiller <ctiller@google.com> | 2017-04-12 09:43:34 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-04-12 09:43:34 -0700 |
commit | 7fea75125846a0326dfa907c5a310f62d5f8e567 (patch) | |
tree | d200f0198ae804285ef6db54f6d96b8151c34c85 | |
parent | 9f99c303d01c706306eb54a5cfd0a23e1e76c6e3 (diff) |
ubsan fixes
-rw-r--r-- | src/core/lib/iomgr/sockaddr_utils.c | 4 | ||||
-rw-r--r-- | src/core/lib/slice/slice.c | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/core/lib/iomgr/sockaddr_utils.c b/src/core/lib/iomgr/sockaddr_utils.c index 9d2732666b..a6a4cac3e2 100644 --- a/src/core/lib/iomgr/sockaddr_utils.c +++ b/src/core/lib/iomgr/sockaddr_utils.c @@ -55,7 +55,9 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address *resolved_addr, GPR_ASSERT(resolved_addr != resolved_addr4_out); const struct sockaddr *addr = (const struct sockaddr *)resolved_addr->addr; struct sockaddr_in *addr4_out = - (struct sockaddr_in *)resolved_addr4_out->addr; + resolved_addr4_out == NULL + ? NULL + : (struct sockaddr_in *)resolved_addr4_out->addr; if (addr->sa_family == AF_INET6) { const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr; if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix, diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index da5dc3e52a..a2fcbbdbdf 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -383,8 +383,9 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { } int grpc_slice_default_eq_impl(grpc_slice a, grpc_slice b) { - return GRPC_SLICE_LENGTH(a) == GRPC_SLICE_LENGTH(b) && - 0 == memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), + if (GRPC_SLICE_LENGTH(a) != GRPC_SLICE_LENGTH(b)) return false; + if (GRPC_SLICE_LENGTH(a) == 0) return true; + return 0 == memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), GRPC_SLICE_LENGTH(a)); } |