From b65a8a963045966d42793ccb6b16f01259f10e1c Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Fri, 21 Oct 2016 17:07:06 -0700 Subject: Check the length of path name Use the length of sockaddr_un.sun_path --- src/core/lib/iomgr/unix_sockets_posix.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/core/lib/iomgr/unix_sockets_posix.c b/src/core/lib/iomgr/unix_sockets_posix.c index 030acd9811..ed646f2b79 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.c +++ b/src/core/lib/iomgr/unix_sockets_posix.c @@ -45,6 +45,7 @@ #include #include +#include void grpc_create_socketpair_if_unix(int sv[2]) { GPR_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0); @@ -54,6 +55,16 @@ grpc_error *grpc_resolve_unix_domain_address(const char *name, grpc_resolved_addresses **addrs) { struct sockaddr_un *un; + if (strlen(name) > sizeof(GPR_ARRAY_SIZE(un->sun_path) - 1)) { + char *err_msg; + grpc_error *err; + gpr_asprintf(&err_msg, + "Path name should not have more than %" PRIuPTR " characters.", + GPR_ARRAY_SIZE(un->sun_path) - 1); + err = GRPC_ERROR_CREATE(err_msg); + gpr_free(err_msg); + return err; + } *addrs = gpr_malloc(sizeof(grpc_resolved_addresses)); (*addrs)->naddrs = 1; (*addrs)->addrs = gpr_malloc(sizeof(grpc_resolved_address)); -- cgit v1.2.3