]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ftplistparser: add two overflow preventions
authorDaniel Stenberg <daniel@haxx.se>
Tue, 20 May 2025 13:46:41 +0000 (15:46 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 20 May 2025 14:08:29 +0000 (16:08 +0200)
These two conditions probably cannot actually happen, but these two
checks make that certain and should please the static code analyzers.

Pointed out by Coverity

Closes #17397

lib/ftplistparser.c

index f416308e164104d67d21d5c83112f7076e994c4e..aaf91f311fe512f50b8ccb563442c8b961b1ad82 100644 (file)
@@ -485,7 +485,7 @@ static CURLcode parse_unix(struct Curl_easy *data,
     switch(parser->state.UNIX.sub.hlinks) {
     case PL_UNIX_HLINKS_PRESPACE:
       if(c != ' ') {
-        if(ISDIGIT(c)) {
+        if(ISDIGIT(c) && len) {
           parser->item_offset = len - 1;
           parser->item_length = 1;
           parser->state.UNIX.sub.hlinks = PL_UNIX_HLINKS_NUMBER;
@@ -850,7 +850,7 @@ static CURLcode parse_winnt(struct Curl_easy *data,
   case PL_WINNT_DIRORSIZE:
     switch(parser->state.NT.sub.dirorsize) {
     case PL_WINNT_DIRORSIZE_PRESPACE:
-      if(c != ' ') {
+      if(c != ' ' && len) {
         parser->item_offset = len - 1;
         parser->item_length = 1;
         parser->state.NT.sub.dirorsize = PL_WINNT_DIRORSIZE_CONTENT;