Check the length of path name

Use the length of sockaddr_un.sun_path
pull/8464/head
Yuchen Zeng 8 years ago
parent b997cf6fde
commit b65a8a9630
  1. 11
      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));

Loading…
Cancel
Save