diff options
| author | Jakob Unterwurzacher | 2024-09-03 16:00:24 +0200 | 
|---|---|---|
| committer | Jakob Unterwurzacher | 2024-09-03 16:01:46 +0200 | 
| commit | 2c01b1ab3774ace723b2700fc539dda5f0350633 (patch) | |
| tree | 1a6eb88a9559ab2062db379c48e9cbd61f9c812e /tests | |
| parent | 40abf968eddd54b6c03ac064d6e42cc6f1083146 (diff) | |
ctlsock: delete colliding orphaned socket file
Detect and delete an orphaned socket file that collides with
the ctlsock we want to create.
Fixes https://github.com/rfjakob/gocryptfs/issues/776
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cli/cli_test.go | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index 686d14c..b2f9f40 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -4,6 +4,7 @@ package cli  import (  	"bytes"  	"encoding/hex" +	"errors"  	"fmt"  	"io/ioutil"  	"os" @@ -1033,3 +1034,39 @@ func TestMountCreat(t *testing.T) {  		test_helpers.UnmountPanic(mnt)  	}  } + +// https://github.com/rfjakob/gocryptfs/issues/776 +func TestOrphanedSocket(t *testing.T) { +	cDir := test_helpers.InitFS(t) +	ctlSock := cDir + ".sock" +	mnt := cDir + ".mnt" +	test_helpers.MountOrFatal(t, cDir, mnt, "-extpass", "echo test", "-wpanic=false", "-ctlsock", ctlSock) + +	mnt2 := cDir + ".mnt2" +	err := test_helpers.Mount(cDir, mnt2, false, "-extpass", "echo test", "-wpanic=false", "-ctlsock", ctlSock) +	exitCode := test_helpers.ExtractCmdExitCode(err) +	if exitCode != exitcodes.CtlSock { +		t.Errorf("wrong exit code: want=%d, have=%d", exitcodes.CtlSock, exitCode) +	} +	test_helpers.UnmountPanic(mnt) + +	// Unmount returns before the gocryptfs process has terminated and before the +	// socket file has been deleted. Wait out the deletion. +	for i := 0; i < 100; i++ { +		_, err := os.Stat(ctlSock) +		if errors.Is(err, os.ErrNotExist) { +			break +		} +		time.Sleep(time.Millisecond) +	} + +	// Create orphaned socket file +	err = syscall.Mknod(ctlSock, syscall.S_IFSOCK|0666, 0) +	if err != nil { +		t.Fatal(err) +	} + +	// Should delete the socket file automatically and the mount should work +	test_helpers.MountOrFatal(t, cDir, mnt, "-extpass", "echo test", "-wpanic=false", "-ctlsock", ctlSock) +	test_helpers.UnmountPanic(mnt) +} | 
