Get rid of the deprecated *LEN constants in favour of the new

*SIZ constants that include the trailing \0 byte.
This commit is contained in:
Hartmut Brandt 2004-01-26 14:05:31 +00:00
parent 9220eb85cb
commit 87e2c66a6a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=125028
12 changed files with 64 additions and 65 deletions

View File

@ -549,7 +549,7 @@ ng_make_node(const char *typename, node_p *nodepp)
/* Locate the node type */
if ((type = ng_findtype(typename)) == NULL) {
char filename[NG_TYPELEN + 4];
char filename[NG_TYPESIZ + 3];
linker_file_t lf;
int error;
@ -816,7 +816,7 @@ ng_name_node(node_p node, const char *name)
node_p node2;
/* Check the name is valid */
for (i = 0; i < NG_NODELEN + 1; i++) {
for (i = 0; i < NG_NODESIZ; i++) {
if (name[i] == '\0' || name[i] == '.' || name[i] == ':')
break;
}
@ -837,7 +837,7 @@ ng_name_node(node_p node, const char *name)
}
/* copy it */
strncpy(NG_NODE_NAME(node), name, NG_NODELEN);
strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ);
return (0);
}
@ -986,7 +986,7 @@ ng_add_hook(node_p node, const char *name, hook_p *hookp)
NG_NODE_REF(node); /* each hook counts as a reference */
/* Set hook name */
strncpy(NG_HOOK_NAME(hook), name, NG_HOOKLEN);
strlcpy(NG_HOOK_NAME(hook), name, NG_HOOKSIZ);
/*
* Check if the node type code has something to say about it
@ -1145,7 +1145,7 @@ ng_newtype(struct ng_type *tp)
/* Check version and type name fields */
if ((tp->version != NG_ABI_VERSION)
|| (namelen == 0)
|| (namelen > NG_TYPELEN)) {
|| (namelen >= NG_TYPESIZ)) {
TRAP_ERROR();
return (EINVAL);
}
@ -1349,7 +1349,7 @@ ng_con_nodes(node_p node, const char *name, node_p node2, const char *name2)
NG_HOOK_REF(hook); /* Add a ref for the peer to each*/
NG_HOOK_REF(hook2);
hook2->hk_node = &ng_deadnode;
strncpy(NG_HOOK_NAME(hook2), name2, NG_HOOKLEN);
strlcpy(NG_HOOK_NAME(hook2), name2, NG_HOOKSIZ);
/*
* Queue the function above.
@ -1569,7 +1569,7 @@ int
ng_path2noderef(node_p here, const char *address,
node_p *destp, hook_p *lasthook)
{
char fullpath[NG_PATHLEN + 1];
char fullpath[NG_PATHSIZ];
char *nodename, *path, pbuf[2];
node_p node, oldnode;
char *cp;
@ -2553,8 +2553,8 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
/* Fill in node info */
ni = (struct nodeinfo *) resp->data;
if (NG_NODE_HAS_NAME(here))
strncpy(ni->name, NG_NODE_NAME(here), NG_NODELEN);
strncpy(ni->type, here->nd_type->name, NG_TYPELEN);
strcpy(ni->name, NG_NODE_NAME(here));
strcpy(ni->type, here->nd_type->name);
ni->id = ng_node2ID(here);
ni->hooks = here->nd_numhooks;
break;
@ -2578,8 +2578,8 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
/* Fill in node info */
if (NG_NODE_HAS_NAME(here))
strncpy(ni->name, NG_NODE_NAME(here), NG_NODELEN);
strncpy(ni->type, here->nd_type->name, NG_TYPELEN);
strcpy(ni->name, NG_NODE_NAME(here));
strcpy(ni->type, here->nd_type->name);
ni->id = ng_node2ID(here);
/* Cycle through the linked list of hooks */
@ -2594,14 +2594,13 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
}
if (NG_HOOK_NOT_VALID(hook))
continue;
strncpy(link->ourhook, NG_HOOK_NAME(hook), NG_HOOKLEN);
strncpy(link->peerhook,
NG_PEER_HOOK_NAME(hook), NG_HOOKLEN);
strcpy(link->ourhook, NG_HOOK_NAME(hook));
strcpy(link->peerhook, NG_PEER_HOOK_NAME(hook));
if (NG_PEER_NODE_NAME(hook)[0] != '\0')
strncpy(link->nodeinfo.name,
NG_PEER_NODE_NAME(hook), NG_NODELEN);
strncpy(link->nodeinfo.type,
NG_PEER_NODE(hook)->nd_type->name, NG_TYPELEN);
strcpy(link->nodeinfo.name,
NG_PEER_NODE_NAME(hook));
strcpy(link->nodeinfo.type,
NG_PEER_NODE(hook)->nd_type->name);
link->nodeinfo.id = ng_node2ID(NG_PEER_NODE(hook));
link->nodeinfo.hooks = NG_PEER_NODE(hook)->nd_numhooks;
ni->hooks++;
@ -2652,8 +2651,8 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
if (!unnamed && (! NG_NODE_HAS_NAME(node)))
continue;
if (NG_NODE_HAS_NAME(node))
strncpy(np->name, NG_NODE_NAME(node), NG_NODELEN);
strncpy(np->type, node->nd_type->name, NG_TYPELEN);
strcpy(np->name, NG_NODE_NAME(node));
strcpy(np->type, node->nd_type->name);
np->id = ng_node2ID(node);
np->hooks = node->nd_numhooks;
nl->numnames++;
@ -2695,7 +2694,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
__func__, "types");
break;
}
strncpy(tp->type_name, type->name, NG_TYPELEN);
strcpy(tp->type_name, type->name);
tp->numnodes = type->refs - 1; /* don't count list */
tl->numtypes++;
}

View File

@ -49,9 +49,9 @@
/* Program structure for one hook */
struct ng_bpf_hookprog {
char thisHook[NG_HOOKLEN+1]; /* name of hook */
char ifMatch[NG_HOOKLEN+1]; /* match dest hook */
char ifNotMatch[NG_HOOKLEN+1]; /* !match dest hook */
char thisHook[NG_HOOKSIZ]; /* name of hook */
char ifMatch[NG_HOOKSIZ]; /* match dest hook */
char ifNotMatch[NG_HOOKSIZ]; /* !match dest hook */
int32_t bpf_prog_len; /* #isns in program */
struct bpf_insn bpf_prog[]; /* bpf program */
};
@ -94,9 +94,9 @@ struct ng_bpf_hookstat {
enum {
NGM_BPF_SET_PROGRAM = 1, /* supply a struct ng_bpf_hookprog */
NGM_BPF_GET_PROGRAM, /* returns a struct ng_bpf_hookprog */
NGM_BPF_GET_STATS, /* supply name as char[NG_HOOKLEN+1] */
NGM_BPF_CLR_STATS, /* supply name as char[NG_HOOKLEN+1] */
NGM_BPF_GETCLR_STATS, /* supply name as char[NG_HOOKLEN+1] */
NGM_BPF_GET_STATS, /* supply name as char[NG_HOOKSIZ] */
NGM_BPF_CLR_STATS, /* supply name as char[NG_HOOKSIZ] */
NGM_BPF_GETCLR_STATS, /* supply name as char[NG_HOOKSIZ] */
};
#endif /* _NETGRAPH_NG_BPF_H_ */

View File

@ -1052,7 +1052,7 @@ ng_bridge_timeout(void *arg)
static const char *
ng_bridge_nodename(node_p node)
{
static char name[NG_NODELEN+1];
static char name[NG_NODESIZ];
if (NG_NODE_NAME(node) != NULL)
snprintf(name, sizeof(name), "%s", NG_NODE_NAME(node));

View File

@ -96,7 +96,7 @@ struct ngd_softc {
SLIST_HEAD(, ngd_connection) head;
node_p node;
char nodename[NG_NODELEN + 1];
char nodename[NG_NODESIZ];
} ngd_softc;
/* the per connection receiving queue maximum */

View File

@ -72,7 +72,7 @@ struct ng_etfstat {
/* This structure is returned by the NGM_ETF_GET_STATUS command */
struct ng_etffilter {
char matchhook[NG_HOOKLEN + 1]; /* hook name */
char matchhook[NG_HOOKSIZ]; /* hook name */
u_int16_t ethertype; /* this ethertype to this hook */
};

View File

@ -551,7 +551,7 @@ ng_ksocket_newhook(node_p node, hook_p hook, const char *name0)
{
struct thread *td = curthread ? curthread : &thread0; /* XXX broken */
const priv_p priv = NG_NODE_PRIVATE(node);
char *s1, *s2, name[NG_HOOKLEN+1];
char *s1, *s2, name[NG_HOOKSIZ];
int family, type, protocol, error;
/* Check if we're already connected */

View File

@ -71,7 +71,7 @@ struct ng_mesg {
u_int32_t token; /* match with reply */
u_int32_t typecookie; /* node's type cookie */
u_int32_t cmd; /* command identifier */
u_char cmdstr[NG_CMDSTRLEN+1]; /* cmd string + \0 */
u_char cmdstr[NG_CMDSTRSIZ]; /* cmd string + \0 */
} header;
char data[]; /* placeholder for actual data */
};
@ -162,9 +162,9 @@ struct ng_mesg {
#define NGM_SET_FLOW_MANAGER 48 /* send flow control here */
/* Structure used for NGM_MKPEER */
struct ngm_mkpeer {
char type[NG_TYPELEN + 1]; /* peer type */
char ourhook[NG_HOOKLEN + 1]; /* hook name */
char peerhook[NG_HOOKLEN + 1]; /* peer hook name */
char type[NG_TYPESIZ]; /* peer type */
char ourhook[NG_HOOKSIZ]; /* hook name */
char peerhook[NG_HOOKSIZ]; /* peer hook name */
};
/* Keep this in sync with the above structure definition */
@ -177,9 +177,9 @@ struct ngm_mkpeer {
/* Structure used for NGM_CONNECT */
struct ngm_connect {
char path[NG_PATHLEN + 1]; /* peer path */
char ourhook[NG_HOOKLEN + 1]; /* hook name */
char peerhook[NG_HOOKLEN + 1]; /* peer hook name */
char path[NG_PATHSIZ]; /* peer path */
char ourhook[NG_HOOKSIZ]; /* hook name */
char peerhook[NG_HOOKSIZ]; /* peer hook name */
};
/* Keep this in sync with the above structure definition */
@ -192,7 +192,7 @@ struct ngm_connect {
/* Structure used for NGM_NAME */
struct ngm_name {
char name[NG_NODELEN + 1]; /* node name */
char name[NG_NODESIZ]; /* node name */
};
/* Keep this in sync with the above structure definition */
@ -203,7 +203,7 @@ struct ngm_name {
/* Structure used for NGM_RMHOOK */
struct ngm_rmhook {
char ourhook[NG_HOOKLEN + 1]; /* hook name */
char ourhook[NG_HOOKSIZ]; /* hook name */
};
/* Keep this in sync with the above structure definition */
@ -214,8 +214,8 @@ struct ngm_rmhook {
/* Structure used for NGM_NODEINFO */
struct nodeinfo {
char name[NG_NODELEN + 1]; /* node name (if any) */
char type[NG_TYPELEN + 1]; /* peer type */
char name[NG_NODESIZ]; /* node name (if any) */
char type[NG_TYPESIZ]; /* peer type */
ng_ID_t id; /* unique identifier */
u_int32_t hooks; /* number of active hooks */
};
@ -231,8 +231,8 @@ struct nodeinfo {
/* Structure used for NGM_LISTHOOKS */
struct linkinfo {
char ourhook[NG_HOOKLEN + 1]; /* hook name */
char peerhook[NG_HOOKLEN + 1]; /* peer hook */
char ourhook[NG_HOOKSIZ]; /* hook name */
char peerhook[NG_HOOKSIZ]; /* peer hook */
struct nodeinfo nodeinfo;
};
@ -271,8 +271,8 @@ struct namelist {
/* Structure used for NGM_LISTTYPES */
struct typeinfo {
char type_name[NG_TYPELEN + 1]; /* name of type */
u_int32_t numnodes; /* number alive */
char type_name[NG_TYPESIZ]; /* name of type */
u_int32_t numnodes; /* number alive */
};
/* Keep this in sync with the above structure definition */

View File

@ -840,7 +840,7 @@ const struct ng_parse_type ng_parse_fixedstring_type = {
};
const struct ng_parse_fixedstring_info ng_parse_nodebuf_info = {
NG_NODELEN + 1
NG_NODESIZ
};
const struct ng_parse_type ng_parse_nodebuf_type = {
&ng_parse_fixedstring_type,
@ -848,7 +848,7 @@ const struct ng_parse_type ng_parse_nodebuf_type = {
};
const struct ng_parse_fixedstring_info ng_parse_hookbuf_info = {
NG_HOOKLEN + 1
NG_HOOKSIZ
};
const struct ng_parse_type ng_parse_hookbuf_type = {
&ng_parse_fixedstring_type,
@ -856,7 +856,7 @@ const struct ng_parse_type ng_parse_hookbuf_type = {
};
const struct ng_parse_fixedstring_info ng_parse_pathbuf_info = {
NG_PATHLEN + 1
NG_PATHSIZ
};
const struct ng_parse_type ng_parse_pathbuf_type = {
&ng_parse_fixedstring_type,
@ -864,7 +864,7 @@ const struct ng_parse_type ng_parse_pathbuf_type = {
};
const struct ng_parse_fixedstring_info ng_parse_typebuf_info = {
NG_TYPELEN + 1
NG_TYPESIZ
};
const struct ng_parse_type ng_parse_typebuf_type = {
&ng_parse_fixedstring_type,
@ -872,7 +872,7 @@ const struct ng_parse_type ng_parse_typebuf_type = {
};
const struct ng_parse_fixedstring_info ng_parse_cmdbuf_info = {
NG_CMDSTRLEN + 1
NG_CMDSTRSIZ
};
const struct ng_parse_type ng_parse_cmdbuf_type = {
&ng_parse_fixedstring_type,

View File

@ -404,11 +404,11 @@ extern const struct ng_parse_type ng_parse_sizedstring_type;
/*
* COMMONLY USED BOUNDED LENGTH STRING TYPES
*/
extern const struct ng_parse_type ng_parse_nodebuf_type; /* NG_NODELEN + 1 */
extern const struct ng_parse_type ng_parse_hookbuf_type; /* NG_HOOKLEN + 1 */
extern const struct ng_parse_type ng_parse_pathbuf_type; /* NG_PATHLEN + 1 */
extern const struct ng_parse_type ng_parse_typebuf_type; /* NG_TYPELEN + 1 */
extern const struct ng_parse_type ng_parse_cmdbuf_type; /* NG_CMDSTRLEN + 1 */
extern const struct ng_parse_type ng_parse_nodebuf_type; /* NG_NODESIZ */
extern const struct ng_parse_type ng_parse_hookbuf_type; /* NG_HOOKSIZ */
extern const struct ng_parse_type ng_parse_pathbuf_type; /* NG_PATHSIZ */
extern const struct ng_parse_type ng_parse_typebuf_type; /* NG_TYPESIZ */
extern const struct ng_parse_type ng_parse_cmdbuf_type; /* NG_CMDSTRSIZ */
/*
* INTEGER TYPES

View File

@ -917,7 +917,7 @@ send_acname(sessp sp, const struct pppoe_tag *tag)
return (ENOMEM);
sts = (struct ngpppoe_sts *)msg->data;
tlen = min(NG_HOOKLEN, ntohs(tag->tag_len));
tlen = min(NG_HOOKSIZ - 1, ntohs(tag->tag_len));
strncpy(sts->hook, tag->tag_data, tlen);
sts->hook[tlen] = '\0';
NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
@ -1763,7 +1763,7 @@ AAA
if (msg == NULL)
return (ENOMEM);
sts = (struct ngpppoe_sts *)msg->data;
strncpy(sts->hook, NG_HOOK_NAME(sp->hook), NG_HOOKLEN + 1);
strncpy(sts->hook, NG_HOOK_NAME(sp->hook), NG_HOOKSIZ);
NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
return (error);
}

View File

@ -115,7 +115,7 @@ struct ngpppoestat {
* and begin negotiation.
*/
struct ngpppoe_init_data {
char hook[NG_HOOKLEN + 1]; /* hook to monitor on */
char hook[NG_HOOKSIZ]; /* hook to monitor on */
u_int16_t data_len; /* Length of the service name */
char data[0]; /* init data goes here */
};
@ -133,7 +133,7 @@ struct ngpppoe_init_data {
* to whoever requested the connection. (close may use this too).
*/
struct ngpppoe_sts {
char hook[NG_HOOKLEN + 1]; /* hook associated with event session */
char hook[NG_HOOKSIZ]; /* hook associated with event session */
};
/* Keep this in sync with the above structure definition */

View File

@ -346,7 +346,7 @@ ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
int len, error;
hook_p hook = NULL;
char hookname[NG_HOOKLEN + 1];
char hookname[NG_HOOKSIZ];
if ((pcbp == NULL) || (control != NULL)) {
error = EINVAL;
@ -373,7 +373,7 @@ ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
*/
hook = LIST_FIRST(&pcbp->sockdata->node->nd_hooks);
} else {
if (len > NG_HOOKLEN) {
if (len >= NG_HOOKSIZ) {
error = EINVAL;
goto release;
}
@ -698,7 +698,7 @@ ng_bind(struct sockaddr *nam, struct ngpcb *pcbp)
return (EINVAL);
}
if ((sap->sg_len < 4)
|| (sap->sg_len > (NG_NODELEN + 3))
|| (sap->sg_len > (NG_NODESIZ + 2))
|| (sap->sg_data[0] == '\0')
|| (sap->sg_data[sap->sg_len - 3] != '\0')) {
TRAP_ERROR;
@ -863,7 +863,7 @@ ngs_rcvdata(hook_p hook, item_p item)
struct ngpcb *const pcbp = priv->datasock;
struct socket *so;
struct sockaddr_ng *addr;
char *addrbuf[NG_HOOKLEN + 1 + 4];
char *addrbuf[NG_HOOKSIZ + 4];
int addrlen;
struct mbuf *m;
@ -877,7 +877,7 @@ ngs_rcvdata(hook_p hook, item_p item)
so = pcbp->ng_socket;
/* Get the return address into a sockaddr. */
addrlen = strlen(NG_HOOK_NAME(hook)); /* <= NG_HOOKLEN */
addrlen = strlen(NG_HOOK_NAME(hook)); /* <= NG_HOOKSIZ - 1 */
addr = (struct sockaddr_ng *) addrbuf;
addr->sg_len = addrlen + 3;
addr->sg_family = AF_NETGRAPH;