Skip to content

Commit

Permalink
fix: dutagent module broker errors on bad file transfers
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Drenhaus <jens.drenhaus@blindspot.software>
  • Loading branch information
jensdrenhaus committed Sep 26, 2024
1 parent 83d6f65 commit 8ca9292
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/dutagent/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dutagent

import (
"context"
"fmt"
"io"
"log"

Expand Down Expand Up @@ -129,13 +130,13 @@ func fromClientWorker(ctx context.Context, stream Stream, s *session) error {
if fileMsg == nil {
log.Println("Received empty file message")

continue // Can this happen?
return fmt.Errorf("bad file transfer: received empty file-message")
}

if s.currentFile == "" {
log.Println("Received file without a request - ignoring!")
log.Println("Received file without a request")

continue // Ignore unexpected files
return fmt.Errorf("bad file transfer: received file-message without a former request")
}

path := fileMsg.GetPath()
Expand All @@ -144,13 +145,13 @@ func fromClientWorker(ctx context.Context, stream Stream, s *session) error {
if content == nil {
log.Println("Received file message with empty content")

continue // Can this happen?
return fmt.Errorf("bad file transfer: received file-message without content")
}

if path != s.currentFile {
log.Printf("Received unexpected file %q - ignoring!", path)

continue // Ignore unexpected files
return fmt.Errorf("bad file transfer: received file-message %q but requested %q", path, s.currentFile)
}

log.Printf("Server received file %q from client", path)
Expand Down

0 comments on commit 8ca9292

Please sign in to comment.