Skip to content

Commit d186dff

Browse files
parth-opensrcgvisor-bot
authored andcommitted
nlmsg: Fix buffer update for NestedAttr.
For NestedAttr.PutAttr, the buffer may start pointing to another address incase the buffer doesn't has enough capacity. Updated NestedAttr to point to the correct address. PiperOrigin-RevId: 842321572
1 parent 561ff6d commit d186dff

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pkg/sentry/socket/netlink/nlmsg/message.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ func (n *NestedAttr) PutAttr(atype uint16, v marshal.Marshallable) {
219219
buf: *n,
220220
}
221221
m.PutAttr(atype, v)
222+
// m.buf may have been reallocated in PutAttr, so update the NestedAttr.
223+
*n = m.buf
222224
}
223225

224226
// PutAttrString adds s to the provided NestedAttr, creating nested attributes.
@@ -227,6 +229,8 @@ func (n *NestedAttr) PutAttrString(atype uint16, s string) {
227229
buf: *n,
228230
}
229231
m.PutAttrString(atype, s)
232+
// m.buf may have been reallocated in PutAttrString, so update the NestedAttr.
233+
*n = m.buf
230234
}
231235

232236
// MessageSet contains a series of netlink messages.

0 commit comments

Comments
 (0)