summaryrefslogtreecommitdiffstats
path: root/lib/libnetgraph/msg.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2003-11-14 08:09:01 +0000
committerharti <harti@FreeBSD.org>2003-11-14 08:09:01 +0000
commit5afef437ec54d7ed580bdaa624ab0b12f3ee34cc (patch)
tree4d988635293cd2327c4c416a4d2f0a7470cb6301 /lib/libnetgraph/msg.c
parent1f9203cd5b28f620e81b7be1684d19b587cf56c3 (diff)
downloadFreeBSD-src-5afef437ec54d7ed580bdaa624ab0b12f3ee34cc.zip
FreeBSD-src-5afef437ec54d7ed580bdaa624ab0b12f3ee34cc.tar.gz
Use the new defines that include the trailing '\0' in the code.
Replace occurences of the magic constant 2 with an offsetof macro call that computes the size of the leading members of the sockaddr. Use strlcpy instead of sprintf where appropriate. Document the new changes in the man page.
Diffstat (limited to 'lib/libnetgraph/msg.c')
-rw-r--r--lib/libnetgraph/msg.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/libnetgraph/msg.c b/lib/libnetgraph/msg.c
index 2c2565f..927a31a 100644
--- a/lib/libnetgraph/msg.c
+++ b/lib/libnetgraph/msg.c
@@ -76,7 +76,7 @@ NgSendMsg(int cs, const char *path,
msg.header.token = gMsgId;
msg.header.flags = NGF_ORIG;
msg.header.cmd = cmd;
- snprintf(msg.header.cmdstr, NG_CMDSTRLEN + 1, "cmd%d", cmd);
+ snprintf(msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd);
/* Deliver message */
if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0)
@@ -175,7 +175,7 @@ static int
NgDeliverMsg(int cs, const char *path,
const struct ng_mesg *hdr, const void *args, size_t arglen)
{
- u_char sgbuf[NG_PATHLEN + 3];
+ u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
u_char *buf = NULL;
struct ng_mesg *msg;
@@ -203,8 +203,9 @@ NgDeliverMsg(int cs, const char *path,
/* Prepare socket address */
sg->sg_family = AF_NETGRAPH;
- snprintf(sg->sg_data, NG_PATHLEN + 1, "%s", path);
- sg->sg_len = strlen(sg->sg_data) + 3;
+ /* XXX handle overflow */
+ strlcpy(sg->sg_data, path, NG_PATHSIZ);
+ sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
/* Debugging */
if (_gNgDebugLevel >= 2) {
@@ -240,7 +241,7 @@ done:
int
NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path)
{
- u_char sgbuf[NG_PATHLEN + sizeof(struct sockaddr_ng)];
+ u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
int len, sglen = sizeof(sgbuf);
int errnosv;
@@ -254,7 +255,7 @@ NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path)
goto errout;
}
if (path != NULL)
- snprintf(path, NG_PATHLEN + 1, "%s", sg->sg_data);
+ strlcpy(path, sg->sg_data, NG_PATHSIZ);
/* Debugging */
if (_gNgDebugLevel >= 2) {
OpenPOWER on IntegriCloud