s3:libsmb: use clistr_pull_talloc() for short_name in interpret_long_filename()
authorStefan Metzmacher <metze@samba.org>
Wed, 6 Jul 2011 16:57:27 +0000 (18:57 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 7 Jul 2011 12:49:44 +0000 (14:49 +0200)
metze

source3/include/client.h
source3/libsmb/clilist.c
source3/torture/masktest.c
source3/torture/torture.c

index a853e90af643d140092eaa94abf1af2becb68f37..40040f4bdf04bbd556590df2aab1959b44ef82d1 100644 (file)
@@ -152,7 +152,7 @@ struct file_info {
        struct timespec atime_ts;
        struct timespec ctime_ts;
        char *name;
-       char short_name[13*3]; /* the *3 is to cope with multi-byte */
+       char *short_name;
 };
 
 #define CLI_FULL_CONNECTION_DONT_SPNEGO 0x0001
index 0792e4057b1f479751b609bdfd1f482c543ce67a..a9270fbb3521992485cdab305393f4606d4b3e7c 100644 (file)
@@ -189,9 +189,16 @@ static size_t interpret_long_filename(TALLOC_CTX *ctx,
                                return pdata_end - base;
                        }
                        p += 2;
-                       clistr_pull(base_ptr, finfo->short_name, p,
-                                   sizeof(finfo->short_name),
-                                   slen, STR_UNICODE);
+                       ret = clistr_pull_talloc(ctx,
+                                               base_ptr,
+                                               recv_flags2,
+                                               &finfo->short_name,
+                                               p,
+                                               slen,
+                                               STR_UNICODE);
+                       if (ret == (size_t)-1) {
+                               return pdata_end - base;
+                       }
                        p += 24; /* short name? */
                        if (p + namelen < p || p + namelen > pdata_end) {
                                return pdata_end - base;
@@ -258,9 +265,10 @@ static bool interpret_short_filename(TALLOC_CTX *ctx,
        }
 
        if (finfo->name) {
-               strlcpy(finfo->short_name,
-                       finfo->name,
-                       sizeof(finfo->short_name));
+               finfo->short_name = talloc_strdup(ctx, finfo->name);
+               if (finfo->short_name == NULL) {
+                       return false;
+               }
        }
        return true;
 }
index 9bb34dfe4594c7aa6894f1708778c276d63e249b..6b9c302aa3741f5f053f5ad74105d0b0a4523c98 100644 (file)
@@ -267,7 +267,8 @@ static NTSTATUS listfn(const char *mnt, struct file_info *f, const char *s,
                return NT_STATUS_OK;
        }
 
-       fstrcpy(state->short_name, f->short_name);
+
+       fstrcpy(state->short_name, f->short_name ? f->short_name : "");
        strlower_m(state->short_name);
        *state->pp_long_name = SMB_STRDUP(f->name);
        if (!*state->pp_long_name) {
index 7e2a5e7beb0c82b840c9bd09dc97f77472399fc8..65cad3e967bafd1c6e80c55296fb2083261666ae 100644 (file)
@@ -7077,13 +7077,13 @@ static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
 #endif
 
        if (strchr(force_shortname_chars, i)) {
-               if (!finfo->short_name[0]) {
+               if (!finfo->short_name) {
                        /* Shortname not created when it should be. */
                        d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
                                __location__, finfo->name, i);
                        s->val = true;
                }
-       } else if (finfo->short_name[0]){
+       } else if (finfo->short_name){
                /* Shortname created when it should not be. */
                d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
                        __location__, finfo->short_name, finfo->name);