@@ -606,9 +606,14 @@ func (c *clientHandler) handleGenericHash(param string, algo HASHAlgo, isCustomM
606606 return nil
607607 }
608608
609- args := strings .SplitN (param , " " , 3 )
610- info , err := c .driver .Stat (args [0 ])
609+ args , err := unquoteSpaceSeparatedParams (param )
610+ if err != nil || len (args ) == 0 {
611+ c .writeMessage (StatusSyntaxErrorParameters , fmt .Sprintf ("invalid HASH parameters: %v" , param ))
612+
613+ return nil //nolint:nilerr
614+ }
611615
616+ info , err := c .driver .Stat (args [0 ])
612617 if err != nil {
613618 c .writeMessage (StatusActionNotTaken , fmt .Sprintf ("%v: %v" , param , err ))
614619
@@ -627,25 +632,11 @@ func (c *clientHandler) handleGenericHash(param string, algo HASHAlgo, isCustomM
627632 // to support partial hash also for the HASH command, we should implement RANG,
628633 // but it applies also to uploads/downloads and so it complicates their handling,
629634 // we'll add this support in future improvements
630- if isCustomMode { //nolint:nestif // too much effort to change for now
631- // for custom command the range can be specified in this way:
632- // XSHA1 <file> <start> <end>
633- if len (args ) > 1 {
634- start , err = strconv .ParseInt (args [1 ], 10 , 64 )
635- if err != nil {
636- c .writeMessage (StatusSyntaxErrorParameters , fmt .Sprintf ("invalid start offset %v: %v" , args [1 ], err ))
637-
638- return nil
639- }
640- }
641-
642- if len (args ) > 2 {
643- end , err = strconv .ParseInt (args [2 ], 10 , 64 )
644- if err != nil {
645- c .writeMessage (StatusSyntaxErrorParameters , fmt .Sprintf ("invalid end offset %v: %v" , args [2 ], err ))
635+ if isCustomMode {
636+ if err = getPartialHASHRange (args , & start , & end ); err != nil {
637+ c .writeMessage (StatusSyntaxErrorParameters , err .Error ())
646638
647- return nil
648- }
639+ return nil
649640 }
650641 }
651642
@@ -747,6 +738,30 @@ func (c *clientHandler) closeUnchecked(file io.Closer) {
747738 }
748739}
749740
741+ func getPartialHASHRange (args []string , start * int64 , end * int64 ) error {
742+ // for custom HASH commands the range can be specified in this way:
743+ // XSHA1 <file> <start> <end>
744+ if len (args ) > 1 {
745+ val , err := strconv .ParseInt (args [1 ], 10 , 64 )
746+ if err != nil {
747+ return fmt .Errorf ("invalid start offset %v: %w" , args [1 ], err )
748+ }
749+
750+ * start = val
751+ }
752+
753+ if len (args ) > 2 {
754+ val , err := strconv .ParseInt (args [2 ], 10 , 64 )
755+ if err != nil {
756+ return fmt .Errorf ("invalid end offset %v: %w" , args [1 ], err )
757+ }
758+
759+ * end = val
760+ }
761+
762+ return nil
763+ }
764+
750765// This method split params by spaces, except when the space is inside quotes.
751766// It was introduced to support COMB command. Supported COMB examples:
752767//
0 commit comments