r14351: Ensure we use the minimum of PATH_MAX and sizeof(pstring).
authorJeremy Allison <jra@samba.org>
Mon, 13 Mar 2006 22:49:56 +0000 (22:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:15:26 +0000 (11:15 -0500)
Fix Coverity #59.
Jeremy.

source/client/client.c

index 0126e17c5bd33807fe361d41b367324c33d1d140..1d42fd2995a9f716a5052ef4a772bb53118f8058 100644 (file)
@@ -2919,16 +2919,22 @@ static char **remote_completion(const char *text, int len)
        info.text = text;
        info.len = len;
                
-       if (len >= PATH_MAX)
+       if (len >= MIN(PATH_MAX,sizeof(pstring))) {
                return(NULL);
+       }
 
        info.matches = SMB_MALLOC_ARRAY(char *,MAX_COMPLETIONS);
-       if (!info.matches) return NULL;
+       if (!info.matches) {
+               return NULL;
+       }
        info.matches[0] = NULL;
 
-       for (i = len-1; i >= 0; i--)
-               if ((text[i] == '/') || (text[i] == '\\'))
+       for (i = len-1; i >= 0; i--) {
+               if ((text[i] == '/') || (text[i] == '\\')) {
                        break;
+               }
+       }
+
        info.text = text+i+1;
        info.samelen = info.len = len-i-1;
 
@@ -2936,8 +2942,9 @@ static char **remote_completion(const char *text, int len)
                strncpy(info.dirmask, text, i+1);
                info.dirmask[i+1] = 0;
                pstr_sprintf(dirmask, "%s%*s*", cur_dir, i-1, text);
-       } else
+       } else {
                pstr_sprintf(dirmask, "%s*", cur_dir);
+       }
 
        if (cli_list(cli, dirmask, aDIR | aSYSTEM | aHIDDEN, completion_remote_filter, &info) < 0)
                goto cleanup;