netgraph: increase size of sockaddr_ng to match maximum node name

The ng_socket(4) node already writes more than declared size of the
struct at least in the in ng_getsockaddr().  Make size match size of
a node name.  The value is pasted instead of including ng_message.h
into ng_socket.h.  This is external API and we want to keep it stable
even if NG_NODESIZ is redefined in a kernel build.

Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42690
This commit is contained in:
Gleb Smirnoff 2023-11-27 20:10:52 -08:00
parent c596126a5d
commit 4064a1108b
3 changed files with 5 additions and 7 deletions

View file

@ -42,7 +42,10 @@
#ifndef _NETGRAPH_NG_MESSAGE_H_
#define _NETGRAPH_NG_MESSAGE_H_
/* ASCII string size limits */
/*
* ASCII string size limits
* Check with struct sockaddr_ng if changing.
*/
#define NG_TYPESIZ 32 /* max type name len (including null) */
#define NG_HOOKSIZ 32 /* max hook name len (including null) */
#define NG_NODESIZ 32 /* max node name len (including null) */

View file

@ -60,7 +60,7 @@ enum {
struct sockaddr_ng {
unsigned char sg_len; /* total length */
sa_family_t sg_family; /* address family */
char sg_data[14]; /* actually longer; address value */
char sg_data[32]; /* see NG_NODESIZ in ng_message.h */
};
#endif /* _NETGRAPH_NG_SOCKET_H_ */

View file

@ -53,12 +53,7 @@ ATF_TC_BODY(getsockname, tc)
/* Named node. */
ATF_REQUIRE(NgMkSockNode(name, &cs, NULL) == 0);
ATF_REQUIRE(getsockname(cs, (struct sockaddr *)&sg, &len) == 0);
#if 0
/* sockaddr_ng truncates name now. */
ATF_REQUIRE(strcmp(sg.sg_data, NAME) == 0);
#else
ATF_REQUIRE(strncmp(sg.sg_data, NAME, sizeof(sg.sg_data)) == 0);
#endif
}
ATF_TP_ADD_TCS(tp)