diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-25 11:11:35 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-28 11:39:03 -0700 |
| commit | 601c64ec4f2b8a41fba59d31a987090feeb69e84 (patch) | |
| tree | 985ec57b3e238b4eed9b42ddaa4736b949df8c6f /src/transport/ipc/ipc.c | |
| parent | 595da8102f3e34e95dad351bc55cd45421616723 (diff) | |
| download | nng-601c64ec4f2b8a41fba59d31a987090feeb69e84.tar.gz nng-601c64ec4f2b8a41fba59d31a987090feeb69e84.tar.bz2 nng-601c64ec4f2b8a41fba59d31a987090feeb69e84.zip | |
Introduce utility safe string handling functions.
We have our versions of strdup, strlcat, and strlcpy.
This means we can avoid using snprintf() in many cases
(saving cycles), and we can get safer checks. We use
the platform supplied versions of these if they exist
(wrapping with nni_xxx versions.)
Diffstat (limited to 'src/transport/ipc/ipc.c')
| -rw-r--r-- | src/transport/ipc/ipc.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index e5e19f36..b2c382fb 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -486,20 +486,29 @@ nni_ipc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) nni_ipc_ep * ep; int rv; nni_sockaddr sa; + size_t sz; - if ((strlen(url) > NNG_MAXADDRLEN - 1) || - (strncmp(url, "ipc://", strlen("ipc://")) != 0)) { + if (strncmp(url, "ipc://", strlen("ipc://")) != 0) { return (NNG_EADDRINVAL); } + url += strlen("ipc://"); + sz = sizeof(sa.s_un.s_path.sa_path); sa.s_un.s_path.sa_family = NNG_AF_IPC; - (void) snprintf(sa.s_un.s_path.sa_path, sizeof(sa.s_un.s_path.sa_path), - "%s", url + strlen("ipc://")); + + if (nni_strlcpy(sa.s_un.s_path.sa_path, url, sz) >= sz) { + return (NNG_EADDRINVAL); + } if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); } - url += strlen("ipc://"); + + if (nni_strlcpy(ep->addr, url, sizeof(ep->addr)) >= sizeof(ep->addr)) { + NNI_FREE_STRUCT(ep); + return (NNG_EADDRINVAL); + } + if ((rv = nni_plat_ipc_ep_init(&ep->iep, &sa, mode)) != 0) { NNI_FREE_STRUCT(ep); return (rv); @@ -509,7 +518,6 @@ nni_ipc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) nni_aio_init(&ep->aio, nni_ipc_ep_cb, ep); ep->proto = nni_sock_proto(sock); - (void) snprintf(ep->addr, sizeof(ep->addr), "%s", url); *epp = ep; return (0); |
