diff options
author | Yuchen Zeng <zyc@google.com> | 2016-10-21 17:07:06 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2017-01-17 13:24:01 -0800 |
commit | b65a8a963045966d42793ccb6b16f01259f10e1c (patch) | |
tree | 34b840e7186e7bb10fbc289ee81053b9cef09ff1 /src | |
parent | b997cf6fdeac14c56486d2f65452dc90346b41af (diff) |
Check the length of path name
Use the length of sockaddr_un.sun_path
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lib/iomgr/unix_sockets_posix.c | 11 |
1 files changed, 11 insertions, 0 deletions
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 <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/useful.h> 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)); |