diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c index a69cfa6ded56..660cbd3e1ba8 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; + /* + * 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(data, workBuf, *off); - if (ng_get_composite_elem_default(type, index, workBuf, - workBuf + *off, &tempsize, ctype) == 0 - && bcmp(workBuf + *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;