aboutsummaryrefslogtreecommitdiff
path: root/lib/libnetgraph/sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libnetgraph/sock.c')
-rw-r--r--lib/libnetgraph/sock.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/libnetgraph/sock.c b/lib/libnetgraph/sock.c
index d3bdf59651df..7485baa6830f 100644
--- a/lib/libnetgraph/sock.c
+++ b/lib/libnetgraph/sock.c
@@ -60,7 +60,7 @@ __FBSDID("$FreeBSD$");
int
NgMkSockNode(const char *name, int *csp, int *dsp)
{
- char namebuf[NG_NODELEN + 1];
+ char namebuf[NG_NODESIZ];
int cs = -1; /* control socket */
int ds = -1; /* data socket */
int errnosv;
@@ -93,13 +93,13 @@ NgMkSockNode(const char *name, int *csp, int *dsp)
gotNode:
/* Assign the node the desired name, if any */
if (name != NULL) {
- u_char sbuf[NG_NODELEN + 3];
+ u_char sbuf[NG_NODESIZ + NGSA_OVERHEAD];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
/* Assign name */
- snprintf(sg->sg_data, NG_NODELEN + 1, "%s", name);
+ strlcpy(sg->sg_data, name, NG_NODESIZ);
sg->sg_family = AF_NETGRAPH;
- sg->sg_len = strlen(sg->sg_data) + 3;
+ sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
if (bind(cs, (struct sockaddr *) sg, sg->sg_len) < 0) {
errnosv = errno;
if (_gNgDebugLevel >= 1)
@@ -108,7 +108,7 @@ gotNode:
}
/* Save node name */
- snprintf(namebuf, sizeof(namebuf), "%s", name);
+ strlcpy(namebuf, name, sizeof(namebuf));
} else if (dsp != NULL) {
u_char rbuf[sizeof(struct ng_mesg) + sizeof(struct nodeinfo)];
struct ng_mesg *const resp = (struct ng_mesg *) rbuf;
@@ -135,7 +135,7 @@ gotNode:
/* Create data socket if desired */
if (dsp != NULL) {
- u_char sbuf[NG_NODELEN + 4];
+ u_char sbuf[NG_NODESIZ + 1 + NGSA_OVERHEAD];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
/* Create data socket, initially just "floating" */
@@ -147,9 +147,9 @@ gotNode:
}
/* Associate the data socket with the node */
- snprintf(sg->sg_data, NG_NODELEN + 2, "%s:", namebuf);
+ snprintf(sg->sg_data, NG_NODESIZ + 1, "%s:", namebuf);
sg->sg_family = AF_NETGRAPH;
- sg->sg_len = strlen(sg->sg_data) + 3;
+ sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
if (connect(ds, (struct sockaddr *) sg, sg->sg_len) < 0) {
errnosv = errno;
if (_gNgDebugLevel >= 1)
@@ -211,7 +211,7 @@ NgNameNode(int cs, const char *path, const char *fmt, ...)
int
NgRecvData(int ds, u_char * buf, size_t len, char *hook)
{
- u_char frombuf[NG_HOOKLEN + sizeof(struct sockaddr_ng)];
+ u_char frombuf[NG_HOOKSIZ + NGSA_OVERHEAD];
struct sockaddr_ng *const from = (struct sockaddr_ng *) frombuf;
int fromlen = sizeof(frombuf);
int rtn, errnosv;
@@ -228,7 +228,7 @@ NgRecvData(int ds, u_char * buf, size_t len, char *hook)
/* Copy hook name */
if (hook != NULL)
- snprintf(hook, NG_HOOKLEN + 1, "%s", from->sg_data);
+ strlcpy(hook, from->sg_data, NG_HOOKSIZ);
/* Debugging */
if (_gNgDebugLevel >= 2) {
@@ -250,14 +250,14 @@ NgRecvData(int ds, u_char * buf, size_t len, char *hook)
int
NgSendData(int ds, const char *hook, const u_char * buf, size_t len)
{
- u_char sgbuf[NG_HOOKLEN + sizeof(struct sockaddr_ng)];
+ u_char sgbuf[NG_HOOKSIZ + NGSA_OVERHEAD];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
int errnosv;
/* Set up destination hook */
sg->sg_family = AF_NETGRAPH;
- snprintf(sg->sg_data, NG_HOOKLEN + 1, "%s", hook);
- sg->sg_len = strlen(sg->sg_data) + 3;
+ strlcpy(sg->sg_data, hook, NG_HOOKSIZ);
+ sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
/* Debugging */
if (_gNgDebugLevel >= 2) {