container/inittmpfs: unwrap out of bounds error
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 1m44s
Test / Hakurei (push) Successful in 3m17s
Test / Hpkg (push) Successful in 3m40s
Test / Sandbox (race detector) (push) Successful in 4m13s
Test / Hakurei (race detector) (push) Successful in 5m18s
Test / Flake checks (push) Successful in 1m36s
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 1m44s
Test / Hakurei (push) Successful in 3m17s
Test / Hpkg (push) Successful in 3m40s
Test / Sandbox (race detector) (push) Successful in 4m13s
Test / Hakurei (race detector) (push) Successful in 5m18s
Test / Flake checks (push) Successful in 1m36s
This eliminates generic WrapErr from tmpfs. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
4da6463135
commit
8d472ebf2b
@ -24,6 +24,10 @@ func messageFromError(err error) (string, bool) {
|
|||||||
return m, ok
|
return m, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m, ok := messagePrefix[TmpfsSizeError]("", err); ok {
|
||||||
|
return m, ok
|
||||||
|
}
|
||||||
|
|
||||||
return zeroString, false
|
return zeroString, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ func TestMessageFromError(t *testing.T) {
|
|||||||
{"state", OpStateError("overlay"),
|
{"state", OpStateError("overlay"),
|
||||||
"impossible overlay state reached", true},
|
"impossible overlay state reached", true},
|
||||||
|
|
||||||
|
{"tmpfs", TmpfsSizeError(-1),
|
||||||
|
"tmpfs size -1 out of bounds", true},
|
||||||
|
|
||||||
{"unsupported", errUnique, zeroString, false},
|
{"unsupported", errUnique, zeroString, false},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
@ -3,14 +3,20 @@ package container
|
|||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
. "syscall"
|
. "syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { gob.Register(new(MountTmpfsOp)) }
|
func init() { gob.Register(new(MountTmpfsOp)) }
|
||||||
|
|
||||||
|
type TmpfsSizeError int
|
||||||
|
|
||||||
|
func (e TmpfsSizeError) Error() string {
|
||||||
|
return "tmpfs size " + strconv.Itoa(int(e)) + " out of bounds"
|
||||||
|
}
|
||||||
|
|
||||||
// Tmpfs appends an [Op] that mounts tmpfs on container path [MountTmpfsOp.Path].
|
// Tmpfs appends an [Op] that mounts tmpfs on container path [MountTmpfsOp.Path].
|
||||||
func (f *Ops) Tmpfs(target *Absolute, size int, perm os.FileMode) *Ops {
|
func (f *Ops) Tmpfs(target *Absolute, size int, perm os.FileMode) *Ops {
|
||||||
*f = append(*f, &MountTmpfsOp{SourceTmpfsEphemeral, target, MS_NOSUID | MS_NODEV, size, perm})
|
*f = append(*f, &MountTmpfsOp{SourceTmpfsEphemeral, target, MS_NOSUID | MS_NODEV, size, perm})
|
||||||
@ -36,7 +42,7 @@ func (t *MountTmpfsOp) Valid() bool { return t !=
|
|||||||
func (t *MountTmpfsOp) early(*setupState, syscallDispatcher) error { return nil }
|
func (t *MountTmpfsOp) early(*setupState, syscallDispatcher) error { return nil }
|
||||||
func (t *MountTmpfsOp) apply(_ *setupState, k syscallDispatcher) error {
|
func (t *MountTmpfsOp) apply(_ *setupState, k syscallDispatcher) error {
|
||||||
if t.Size < 0 || t.Size > math.MaxUint>>1 {
|
if t.Size < 0 || t.Size > math.MaxUint>>1 {
|
||||||
return msg.WrapErr(fs.ErrInvalid, fmt.Sprintf("size %d out of bounds", t.Size))
|
return TmpfsSizeError(t.Size)
|
||||||
}
|
}
|
||||||
return k.mountTmpfs(t.FSName, toSysroot(t.Path.String()), t.Flags, t.Size, t.Perm)
|
return k.mountTmpfs(t.FSName, toSysroot(t.Path.String()), t.Flags, t.Size, t.Perm)
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMountTmpfsOp(t *testing.T) {
|
func TestMountTmpfsOp(t *testing.T) {
|
||||||
|
t.Run("size error", func(t *testing.T) {
|
||||||
|
tmpfsSizeError := TmpfsSizeError(-1)
|
||||||
|
want := "tmpfs size -1 out of bounds"
|
||||||
|
if got := tmpfsSizeError.Error(); got != want {
|
||||||
|
t.Errorf("Error: %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||||
{"size oob", new(Params), &MountTmpfsOp{
|
{"size oob", new(Params), &MountTmpfsOp{
|
||||||
Size: -1,
|
Size: -1,
|
||||||
}, nil, nil, nil, msg.WrapErr(fs.ErrInvalid, "size -1 out of bounds")},
|
}, nil, nil, nil, TmpfsSizeError(-1)},
|
||||||
|
|
||||||
{"success", new(Params), &MountTmpfsOp{
|
{"success", new(Params), &MountTmpfsOp{
|
||||||
FSName: "ephemeral",
|
FSName: "ephemeral",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user