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
This commit is contained in:
archie 2002-02-01 02:21:41 +00:00
parent 3a4c649bdc
commit efc80756a1

View File

@ -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;