Skip to content

Commit 65b061b

Browse files
authored
Fix panic when tmp path is inccurate (#280)
* Fix panic when tmp path is inccurate (like with double separators which still valid) and add test-case for it Signed-off-by: s1gnate-sync <[email protected]> * fix linter complaining about thelper finalize_test.go Signed-off-by: s1gnate-sync <[email protected]> --------- Signed-off-by: s1gnate-sync <[email protected]>
1 parent c926038 commit 65b061b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

filesystem/iso9660/finalize_test.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ var (
2323

2424
// test creating an iso with el torito boot
2525
func TestFinalizeElTorito(t *testing.T) {
26+
finalizeElTorito(t, "")
27+
dir, err := os.MkdirTemp("", "workspace")
28+
if err != nil {
29+
t.Fatalf("Failed to create temp dir: %v", err)
30+
}
31+
finalizeElTorito(t, dir)
32+
}
33+
34+
func TestFinalizeElToritoWithInaccurateTmpDir(t *testing.T) {
35+
finalizeElTorito(t, "")
36+
dir, err := os.MkdirTemp("/tmp//", "workspace")
37+
if err != nil {
38+
t.Fatalf("Failed to create temp dir: %v", err)
39+
}
40+
finalizeElTorito(t, dir)
41+
}
42+
43+
//nolint:thelper // this is not a helper function
44+
func finalizeElTorito(t *testing.T, workspace string) {
2645
blocksize := int64(2048)
2746
f, err := os.CreateTemp("", "iso_finalize_test")
2847
defer os.Remove(f.Name())
@@ -31,7 +50,7 @@ func TestFinalizeElTorito(t *testing.T) {
3150
}
3251

3352
b := file.New(f, false)
34-
fs, err := iso9660.Create(b, 0, 0, blocksize, "")
53+
fs, err := iso9660.Create(b, 0, 0, blocksize, workspace)
3554
if err != nil {
3655
t.Fatalf("Failed to iso9660.Create: %v", err)
3756
}

filesystem/iso9660/iso9660.go

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path"
8+
"path/filepath"
89

910
"github.com/diskfs/go-diskfs/backend"
1011
"github.com/diskfs/go-diskfs/filesystem"
@@ -97,6 +98,9 @@ func Create(b backend.Storage, size, start, blocksize int64, workspace string) (
9798
}
9899
}
99100

101+
// sometimes, at least on macos, extra separators in path can cause panic
102+
workdir = filepath.Clean(workdir)
103+
100104
// create root directory
101105
// there is nothing in there
102106
return &FileSystem{

0 commit comments

Comments
 (0)