netgraph-remove-xLEN2.patch

nant, 06/03/2007 11:16 PM

Download (4.6 KB)

View differences:

lib/libnetgraph/sock.c 2007-06-03 23:41:19.000000000 +0100
60 60
int
61 61
NgMkSockNode(const char *name, int *csp, int *dsp)
62 62
{
63
	char namebuf[NG_NODELEN + 1];
63
	char namebuf[NG_NODESIZ];
64 64
	int cs = -1;		/* control socket */
65 65
	int ds = -1;		/* data socket */
66 66
	int errnosv;
......
93 93
gotNode:
94 94
	/* Assign the node the desired name, if any */
95 95
	if (name != NULL) {
96
		u_char sbuf[NG_NODELEN + 3];
96
		u_char sbuf[NG_NODESIZ + 2];
97 97
		struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
98 98

  
99 99
		/* Assign name */
100
		snprintf(sg->sg_data, NG_NODELEN + 1, "%s", name);
100
		snprintf(sg->sg_data, NG_NODESIZ, "%s", name);
101 101
		sg->sg_family = AF_NETGRAPH;
102 102
		sg->sg_len = strlen(sg->sg_data) + 3;
103 103
		if (bind(cs, (struct sockaddr *) sg, sg->sg_len) < 0) {
......
135 135

  
136 136
	/* Create data socket if desired */
137 137
	if (dsp != NULL) {
138
		u_char sbuf[NG_NODELEN + 4];
138
		u_char sbuf[NG_NODESIZ + 3];
139 139
		struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
140 140

  
141 141
		/* Create data socket, initially just "floating" */
......
147 147
		}
148 148

  
149 149
		/* Associate the data socket with the node */
150
		snprintf(sg->sg_data, NG_NODELEN + 2, "%s:", namebuf);
150
		snprintf(sg->sg_data, NG_NODESIZ + 1, "%s:", namebuf);
151 151
		sg->sg_family = AF_NETGRAPH;
152 152
		sg->sg_len = strlen(sg->sg_data) + 3;
153 153
		if (connect(ds, (struct sockaddr *) sg, sg->sg_len) < 0) {
......
211 211
int
212 212
NgRecvData(int ds, u_char * buf, size_t len, char *hook)
213 213
{
214
	u_char frombuf[NG_HOOKLEN + sizeof(struct sockaddr_ng)];
214
	u_char frombuf[NG_HOOKSIZ - 1 + sizeof(struct sockaddr_ng)];
215 215
	struct sockaddr_ng *const from = (struct sockaddr_ng *) frombuf;
216 216
	int fromlen = sizeof(frombuf);
217 217
	int rtn, errnosv;
......
228 228

  
229 229
	/* Copy hook name */
230 230
	if (hook != NULL)
231
		snprintf(hook, NG_HOOKLEN + 1, "%s", from->sg_data);
231
		snprintf(hook, NG_HOOKSIZ, "%s", from->sg_data);
232 232

  
233 233
	/* Debugging */
234 234
	if (_gNgDebugLevel >= 2) {
......
250 250
int
251 251
NgSendData(int ds, const char *hook, const u_char * buf, size_t len)
252 252
{
253
	u_char sgbuf[NG_HOOKLEN + sizeof(struct sockaddr_ng)];
253
	u_char sgbuf[NG_HOOKSIZ - 1 + sizeof(struct sockaddr_ng)];
254 254
	struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
255 255
	int errnosv;
256 256

  
257 257
	/* Set up destination hook */
258 258
	sg->sg_family = AF_NETGRAPH;
259
	snprintf(sg->sg_data, NG_HOOKLEN + 1, "%s", hook);
259
	snprintf(sg->sg_data, NG_HOOKSIZ, "%s", hook);
260 260
	sg->sg_len = strlen(sg->sg_data) + 3;
261 261

  
262 262
	/* Debugging */
263
-- lib/libnetgraph/msg.c.orig	2007-06-03 23:38:47.000000000 +0100
263
++ lib/libnetgraph/msg.c	2007-06-03 23:40:03.000000000 +0100
......
76 76
	msg.header.token = gMsgId;
77 77
	msg.header.flags = NGF_ORIG;
78 78
	msg.header.cmd = cmd;
79
	snprintf(msg.header.cmdstr, NG_CMDSTRLEN + 1, "cmd%d", cmd);
79
	snprintf(msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd);
80 80

  
81 81
	/* Deliver message */
82 82
	if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0)
......
175 175
NgDeliverMsg(int cs, const char *path,
176 176
	const struct ng_mesg *hdr, const void *args, size_t arglen)
177 177
{
178
	u_char sgbuf[NG_PATHLEN + 3];
178
	u_char sgbuf[NG_PATHSIZ + 2];
179 179
	struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
180 180
	u_char *buf = NULL;
181 181
	struct ng_mesg *msg;
......
203 203

  
204 204
	/* Prepare socket address */
205 205
	sg->sg_family = AF_NETGRAPH;
206
	snprintf(sg->sg_data, NG_PATHLEN + 1, "%s", path);
206
	snprintf(sg->sg_data, NG_PATHSIZ, "%s", path);
207 207
	sg->sg_len = strlen(sg->sg_data) + 3;
208 208

  
209 209
	/* Debugging */
......
240 240
int
241 241
NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path)
242 242
{
243
	u_char sgbuf[NG_PATHLEN + sizeof(struct sockaddr_ng)];
243
	u_char sgbuf[NG_PATHSIZ - 1 + sizeof(struct sockaddr_ng)];
244 244
	struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
245 245
	int len, sglen = sizeof(sgbuf);
246 246
	int errnosv;
......
254 254
		goto errout;
255 255
	}
256 256
	if (path != NULL)
257
		snprintf(path, NG_PATHLEN + 1, "%s", sg->sg_data);
257
		snprintf(path, NG_PATHSIZ, "%s", sg->sg_data);
258 258

  
259 259
	/* Debugging */
260 260
	if (_gNgDebugLevel >= 2) {
261
-- lib/libnetgraph/netgraph.3.orig	2007-06-03 23:55:34.000000000 +0100
261
++ lib/libnetgraph/netgraph.3	2007-06-03 23:53:17.000000000 +0100
......
170 170
If
171 171
.Fa "path"
172 172
is non-NULL, it must point to a buffer of at least
173
.Dv "NG_PATHLEN + 1"
173
.Dv "NG_PATHSIZ"
174 174
bytes, which will be filled in (and NUL terminated) with the path to
175 175
the node from which the message was received.
176 176
.Pp
......
209 209
which must be large enough to hold the entire packet.  If
210 210
.Fa "hook"
211 211
is non-NULL, it must point to a buffer of at least
212
.Dv "NG_HOOKLEN + 1"
212
.Dv "NG_HOOKSIZ"
213 213
bytes, which will be filled in (and NUL terminated) with the name of
214 214
the hook on which the data was received.
215 215
.Pp