git: 4064a1108b51 - main - netgraph: increase size of sockaddr_ng to match maximum node name
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 28 Nov 2023 04:12:40 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=4064a1108b51b24903c8d67db21e8dbaf89b475f commit 4064a1108b51b24903c8d67db21e8dbaf89b475f Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2023-11-28 04:10:52 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2023-11-28 04:10:52 +0000 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 --- sys/netgraph/ng_message.h | 5 ++++- sys/netgraph/ng_socket.h | 2 +- tests/sys/netgraph/socket.c | 5 ----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/sys/netgraph/ng_message.h b/sys/netgraph/ng_message.h index 46659bc4cec5..45556ecc609c 100644 --- a/sys/netgraph/ng_message.h +++ b/sys/netgraph/ng_message.h @@ -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) */ diff --git a/sys/netgraph/ng_socket.h b/sys/netgraph/ng_socket.h index 7556ec645f3d..9b537a52814a 100644 --- a/sys/netgraph/ng_socket.h +++ b/sys/netgraph/ng_socket.h @@ -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_ */ diff --git a/tests/sys/netgraph/socket.c b/tests/sys/netgraph/socket.c index b5216dcc2c39..bd40e4358866 100644 --- a/tests/sys/netgraph/socket.c +++ b/tests/sys/netgraph/socket.c @@ -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)