summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorarchie <archie@FreeBSD.org>2002-02-01 02:21:41 +0000
committerarchie <archie@FreeBSD.org>2002-02-01 02:21:41 +0000
commitefc80756a1dc2f98f4ad3342c110290dab2d4520 (patch)
treedcb35d615ee8d7e3698b999898a8cf661be49859 /sys/netgraph
parent3a4c649bdce936d04cb72e382c82cef01cad3f53 (diff)
downloadFreeBSD-src-efc80756a1dc2f98f4ad3342c110290dab2d4520.zip
FreeBSD-src-efc80756a1dc2f98f4ad3342c110290dab2d4520.tar.gz
Some netgraph parse types (such as for the 'value' field in ng_ksocket's
'struct ng_ksocket_sockopt') like to peek into the ng_mesg header for information. Make sure when generating default values that we provide a valid header to peek into. MFC after: 1 week
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/ng_parse.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c
index a69cfa6..660cbd3 100644
--- a/sys/netgraph/ng_parse.c
+++ b/sys/netgraph/ng_parse.c
@@ -1307,6 +1307,8 @@ static int
ng_unparse_composite(const struct ng_parse_type *type, const u_char *data,
int *off, char *cbuf, int cbuflen, const enum comptype ctype)
{
+ const struct ng_mesg *const hdr
+ = (const struct ng_mesg *)(data - sizeof(*hdr));
const int num = ng_get_composite_len(type, data, data + *off, ctype);
const int workSize = 20 * 1024; /* XXX hard coded constant */
int nextIndex = 0, didOne = 0;
@@ -1329,14 +1331,19 @@ ng_unparse_composite(const struct ng_parse_type *type, const u_char *data,
/* Skip any alignment pad bytes */
*off += ng_parse_get_elem_pad(type, index, ctype, *off);
- /* See if element is equal to its default value; skip if so */
- if (*off < workSize) {
- int tempsize = workSize - *off;
-
- bcopy(data, workBuf, *off);
- if (ng_get_composite_elem_default(type, index, workBuf,
- workBuf + *off, &tempsize, ctype) == 0
- && bcmp(workBuf + *off,
+ /*
+ * See if element is equal to its default value; skip if so.
+ * Copy struct ng_mesg header for types that peek into it.
+ */
+ if (sizeof(*hdr) + *off < workSize) {
+ int tempsize = workSize - sizeof(*hdr) - *off;
+
+ bcopy(hdr, workBuf, sizeof(*hdr));
+ bcopy(data + sizeof(*hdr), workBuf, *off);
+ if (ng_get_composite_elem_default(type, index, workBuf
+ + sizeof(*hdr), workBuf + sizeof(*hdr) + *off,
+ &tempsize, ctype) == 0
+ && bcmp(workBuf + sizeof(*hdr) + *off,
data + *off, tempsize) == 0) {
*off += tempsize;
continue;
OpenPOWER on IntegriCloud