From e2869fee8db5f7a94858b551089c45bbb1bd943b Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 23 Feb 2017 09:11:24 -0800 Subject: [PATCH] Simply return 0 on input path too long --- src/core/ext/client_channel/parse_address.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/ext/client_channel/parse_address.c b/src/core/ext/client_channel/parse_address.c index 4b8222824b1..17cfc9795b1 100644 --- a/src/core/ext/client_channel/parse_address.c +++ b/src/core/ext/client_channel/parse_address.c @@ -49,12 +49,12 @@ int parse_unix(grpc_uri *uri, grpc_resolved_address *resolved_addr) { struct sockaddr_un *un = (struct sockaddr_un *)resolved_addr->addr; - + const size_t maxlen = sizeof(un->sun_path); + const size_t path_len = strnlen(uri->path, maxlen); + if (path_len == maxlen) return 0; un->sun_family = AF_UNIX; - strncpy(un->sun_path, uri->path, sizeof(un->sun_path) - 1 /* null term'd */); - un->sun_path[sizeof(un->sun_path) - 1] = '\0'; - resolved_addr->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; - + strcpy(un->sun_path, uri->path); + resolved_addr->len = path_len + sizeof(un->sun_family) + 1; return 1; }