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/tcp | |
| 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/tcp')
| -rw-r--r-- | src/transport/tcp/tcp.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index de1bfa66..f0f07592 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -579,7 +579,9 @@ nni_tcp_ep_init(void **epp, const char *url, nni_sock *sock, int mode) int passive; // Make a copy of the url (to allow for destructive operations) - snprintf(buf, sizeof(buf), "%s", url); + if (nni_strlcpy(buf, url, sizeof(buf)) >= sizeof(buf)) { + return (NNG_EADDRINVAL); + } // Parse the URLs first. rv = nni_tcp_parse_url(buf, &lhost, &lserv, &rhost, &rserv, mode); @@ -620,6 +622,10 @@ nni_tcp_ep_init(void **epp, const char *url, nni_sock *sock, int mode) if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); } + if (nni_strlcpy(ep->addr, url, sizeof(ep->addr)) >= sizeof(ep->addr)) { + NNI_FREE_STRUCT(ep); + return (NNG_EADDRINVAL); + } if ((rv = nni_plat_tcp_ep_init(&ep->tep, &lsa, &rsa, mode)) != 0) { NNI_FREE_STRUCT(ep); @@ -630,7 +636,6 @@ nni_tcp_ep_init(void **epp, const char *url, nni_sock *sock, int mode) nni_aio_init(&ep->aio, nni_tcp_ep_cb, ep); ep->proto = nni_sock_proto(sock); - (void) snprintf(ep->addr, sizeof(ep->addr), "%s", url); *epp = ep; return (0); |
