Skip to content

Commit

Permalink
fixed parsing in HASH commands
Browse files Browse the repository at this point in the history
  • Loading branch information
syncplify authored and fclairamb committed Feb 25, 2024
1 parent 32e7150 commit 4d22eac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion handle_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,12 @@ func (c *clientHandler) handleGenericHash(param string, algo HASHAlgo, isCustomM
return nil
}

args := strings.SplitN(param, " ", 3)
args, err := advSplitN(param, ' ', 3)

if err != nil || len(args) < 1 {
c.writeMessage(StatusSyntaxErrorParameters, fmt.Sprintf("invalid HASH parameters: %v", param))

Check warning on line 599 in handle_files.go

View check run for this annotation

Codecov / codecov/patch

handle_files.go#L599

Added line #L599 was not covered by tests
}

info, err := c.driver.Stat(args[0])

if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions string_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ftpserver

import (
"encoding/csv"
"strings"
)

func advSplitN(s string, sep rune, n int) ([]string, error) {
r := csv.NewReader(strings.NewReader(s))
r.Comma = sep
record, err := r.Read()
if err != nil {

Check failure on line 12 in string_utils.go

View workflow job for this annotation

GitHub Actions / build (1.22)

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 12 in string_utils.go

View workflow job for this annotation

GitHub Actions / build (1.22)

only one cuddle assignment allowed before if statement (wsl)
return nil, err

Check warning on line 13 in string_utils.go

View check run for this annotation

Codecov / codecov/patch

string_utils.go#L13

Added line #L13 was not covered by tests
}
if len(record) > n {

Check failure on line 15 in string_utils.go

View workflow job for this annotation

GitHub Actions / build (1.22)

if statements should only be cuddled with assignments (wsl)

Check failure on line 15 in string_utils.go

View workflow job for this annotation

GitHub Actions / build (1.22)

if statements should only be cuddled with assignments (wsl)
return record[:n], nil

Check warning on line 16 in string_utils.go

View check run for this annotation

Codecov / codecov/patch

string_utils.go#L16

Added line #L16 was not covered by tests
}
return record, nil

Check failure on line 18 in string_utils.go

View workflow job for this annotation

GitHub Actions / build (1.22)

return statements should not be cuddled if block has more than two lines (wsl)

Check failure on line 18 in string_utils.go

View workflow job for this annotation

GitHub Actions / build (1.22)

return statements should not be cuddled if block has more than two lines (wsl)
}

0 comments on commit 4d22eac

Please sign in to comment.