Skip to content

Commit 74e69e9

Browse files
Copilotschollz
andauthored
Fix panic when receiving with --stdout and invalid secret (#993)
* Initial plan * Fix panic when receiving with --stdout and invalid CROC_SECRET Co-authored-by: schollz <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: schollz <[email protected]>
1 parent 7331264 commit 74e69e9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/croc/croc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ func (c *Client) transfer() (err error) {
11751175
}
11761176
}
11771177

1178-
if c.Options.Stdout && !c.Options.IsSender {
1178+
if c.Options.Stdout && !c.Options.IsSender && len(c.FilesToTransfer) > 0 && c.FilesToTransferCurrentNum < len(c.FilesToTransfer) {
11791179
pathToFile := path.Join(
11801180
c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote,
11811181
c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,

src/croc/croc_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,34 @@ func TestCrocError(t *testing.T) {
368368
assert.NotNil(t, err)
369369
}
370370

371+
func TestReceiverStdoutWithInvalidSecret(t *testing.T) {
372+
// Test for issue: panic when receiving with --stdout and invalid CROC_SECRET
373+
// This should fail gracefully without panicking
374+
log.SetLevel("warn")
375+
receiver, err := New(Options{
376+
IsSender: false,
377+
SharedSecret: "invalid-secret-12345",
378+
Debug: true,
379+
RelayAddress: "127.0.0.1:8281",
380+
RelayPassword: "pass123",
381+
Stdout: true, // This is the key flag that triggered the panic
382+
NoPrompt: true,
383+
DisableLocal: true,
384+
Curve: "siec",
385+
Overwrite: true,
386+
})
387+
if err != nil {
388+
t.Errorf("failed to create receiver: %v", err)
389+
return
390+
}
391+
392+
// This should fail but not panic
393+
err = receiver.Receive()
394+
// We expect an error since the secret is invalid and no sender is present
395+
assert.NotNil(t, err)
396+
log.Debugf("Expected error occurred: %v", err)
397+
}
398+
371399
func TestCleanUp(t *testing.T) {
372400
// windows allows files to be deleted only if they
373401
// are not open by another program so the remove actions

0 commit comments

Comments
 (0)