summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-01-26 13:01:26 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-26 13:03:40 -0800
commitce39f82985b95972c545c941be2133b607b4440c (patch)
tree01e450ef81e9b3148161b9241e6b6f2c27893f2d /pkg
parenta90661654d14e77b6442c4a34ced900e2cd9953e (diff)
Implement error on pointers
This improves type-assertion safety. PiperOrigin-RevId: 353931228
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sentry/fs/fdpipe/pipe_state.go4
-rw-r--r--pkg/sentry/fs/fs.go2
-rw-r--r--pkg/sentry/fs/gofer/inode_state.go4
-rw-r--r--pkg/sentry/kernel/kernel.go4
-rw-r--r--pkg/tcpip/tcpip.go2
-rw-r--r--pkg/tcpip/transport/tcp/endpoint_state.go4
6 files changed, 13 insertions, 7 deletions
diff --git a/pkg/sentry/fs/fdpipe/pipe_state.go b/pkg/sentry/fs/fdpipe/pipe_state.go
index af8230a7d..387f713aa 100644
--- a/pkg/sentry/fs/fdpipe/pipe_state.go
+++ b/pkg/sentry/fs/fdpipe/pipe_state.go
@@ -34,7 +34,9 @@ func (p *pipeOperations) beforeSave() {
} else if p.flags.Write {
file, err := p.opener.NonBlockingOpen(context.Background(), fs.PermMask{Write: true})
if err != nil {
- panic(fs.ErrSaveRejection{fmt.Errorf("write-only pipe end cannot be re-opened as %v: %v", p, err)})
+ panic(&fs.ErrSaveRejection{
+ Err: fmt.Errorf("write-only pipe end cannot be re-opened as %#v: %w", p, err),
+ })
}
file.Close()
}
diff --git a/pkg/sentry/fs/fs.go b/pkg/sentry/fs/fs.go
index a020da53b..44587bb37 100644
--- a/pkg/sentry/fs/fs.go
+++ b/pkg/sentry/fs/fs.go
@@ -144,7 +144,7 @@ type ErrSaveRejection struct {
}
// Error returns a sensible description of the save rejection error.
-func (e ErrSaveRejection) Error() string {
+func (e *ErrSaveRejection) Error() string {
return "save rejected due to unsupported file system state: " + e.Err.Error()
}
diff --git a/pkg/sentry/fs/gofer/inode_state.go b/pkg/sentry/fs/gofer/inode_state.go
index a3402e343..141e3c27f 100644
--- a/pkg/sentry/fs/gofer/inode_state.go
+++ b/pkg/sentry/fs/gofer/inode_state.go
@@ -67,7 +67,9 @@ func (i *inodeFileState) beforeSave() {
if i.sattr.Type == fs.RegularFile {
uattr, err := i.unstableAttr(&dummyClockContext{context.Background()})
if err != nil {
- panic(fs.ErrSaveRejection{fmt.Errorf("failed to get unstable atttribute of %s: %v", i.s.inodeMappings[i.sattr.InodeID], err)})
+ panic(&fs.ErrSaveRejection{
+ Err: fmt.Errorf("failed to get unstable atttribute of %s: %w", i.s.inodeMappings[i.sattr.InodeID], err),
+ })
}
i.savedUAttr = &uattr
}
diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go
index 303ae8056..ef4e934a1 100644
--- a/pkg/sentry/kernel/kernel.go
+++ b/pkg/sentry/kernel/kernel.go
@@ -593,8 +593,8 @@ func (k *Kernel) flushWritesToFiles(ctx context.Context) error {
// Wrap this error in ErrSaveRejection so that it will trigger a save
// error, rather than a panic. This also allows us to distinguish Fsync
// errors from state file errors in state.Save.
- return fs.ErrSaveRejection{
- Err: fmt.Errorf("%q was not sufficiently synced: %v", name, err),
+ return &fs.ErrSaveRejection{
+ Err: fmt.Errorf("%q was not sufficiently synced: %w", name, err),
}
}
return nil
diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go
index 4e2c4f906..812ee36ed 100644
--- a/pkg/tcpip/tcpip.go
+++ b/pkg/tcpip/tcpip.go
@@ -195,7 +195,7 @@ type ErrSaveRejection struct {
}
// Error returns a sensible description of the save rejection error.
-func (e ErrSaveRejection) Error() string {
+func (e *ErrSaveRejection) Error() string {
return "save rejected due to unsupported networking state: " + e.Err.Error()
}
diff --git a/pkg/tcpip/transport/tcp/endpoint_state.go b/pkg/tcpip/transport/tcp/endpoint_state.go
index 19c1dc67a..fa8ffaee0 100644
--- a/pkg/tcpip/transport/tcp/endpoint_state.go
+++ b/pkg/tcpip/transport/tcp/endpoint_state.go
@@ -55,7 +55,9 @@ func (e *endpoint) beforeSave() {
case epState.connected() || epState.handshake():
if !e.route.HasSaveRestoreCapability() {
if !e.route.HasDisconncetOkCapability() {
- panic(tcpip.ErrSaveRejection{fmt.Errorf("endpoint cannot be saved in connected state: local %v:%d, remote %v:%d", e.ID.LocalAddress, e.ID.LocalPort, e.ID.RemoteAddress, e.ID.RemotePort)})
+ panic(&tcpip.ErrSaveRejection{
+ Err: fmt.Errorf("endpoint cannot be saved in connected state: local %s:%d, remote %s:%d", e.ID.LocalAddress, e.ID.LocalPort, e.ID.RemoteAddress, e.ID.RemotePort),
+ })
}
e.resetConnectionLocked(tcpip.ErrConnectionAborted)
e.mu.Unlock()