Skip to content

Commit 253e0cc

Browse files
committed
nilaway: netstack/fdbased, netstack/dispatchers
1 parent b760470 commit 253e0cc

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

intra/netstack/dispatchers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ var _ linkDispatcher = (*readVDispatcher)(nil)
184184

185185
// newReadVDispatcher creates a new linkDispatcher that vector reads packets from
186186
// fd and dispatches them to endpoint e. It assumes ownership of fd but not of e.
187-
func newReadVDispatcher(fd *fds, e *endpoint) (linkDispatcher, error) {
187+
func newReadVDispatcher(f *fds, e *endpoint) (linkDispatcher, error) {
188188
d := &readVDispatcher{
189189
e: e,
190190
buf: newIovecBuffer(bufcfg),
191-
mgr: newSupervisor(e, fd.tun()),
191+
mgr: newSupervisor(e, f.tun()),
192192
}
193193
d.mgr.start()
194194

195-
log.I("ns: dispatch: newReadVDispatcher: tun(%s)", fd)
195+
log.I("ns: dispatch: newReadVDispatcher: tun(%s)", f)
196196
return d, nil
197197
}
198198

@@ -269,7 +269,7 @@ func (d *readVDispatcher) io(fds *fds) (bool, tcpip.Error) {
269269
return abort, new(tcpip.ErrAborted)
270270
}
271271

272-
if !fds.ok() {
272+
if fds == nil || !fds.ok() { // nil check for nilaway
273273
log.W("ns: tun(%d): dispatch: fd closed or invalid!", fds.tun())
274274
return abort, new(tcpip.ErrNoSuchFile)
275275
}

intra/netstack/fdbased.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ func (e *endpoint) Swap(fd int) (err error) {
299299
defer e.Unlock()
300300

301301
f, err := newTun(fd) // fd may be invalid (ex: -1)
302-
if err != nil {
302+
if err != nil || f == nil {
303+
f = invalidFds // nilaway
303304
err = log.EE("ns: tun: swap: (%d) err: %v / %v; using invalidfd", fd, err)
304305
}
305306

0 commit comments

Comments
 (0)