]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
vos: do not mix memory allocation methods
authorJeffrey Altman <jaltman@your-file-system.com>
Tue, 28 Dec 2010 00:34:14 +0000 (19:34 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 3 Feb 2011 02:38:35 +0000 (18:38 -0800)
ListVLDB mixed memory allocated with xdr_alloc() and memory
allocated with malloc().  This is not safe to do since it is
possible on some platforms for xdr_alloc() to allocated memory
using a method other than the malloc() linked to the vos
executable.

Instead of stealing the xdr_alloc()'d buffer, allocate a new
buffer and copy the contents.

Reviewed-on: http://gerrit.openafs.org/3600
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
(cherry picked from commit 463b045b9fe4a412877c2a65f5deafb1442c1bf1)

Change-Id: I64f43459a212ceb1b4f89e45a9827fc7b981ff6e
Reviewed-on: http://gerrit.openafs.org/3807
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/volser/vos.c

index 2c55983c34c6b9001c750bdb23f5d40aa5d7cf07..8d06d82e441af60193a4dd2b8e57445652e2067c 100644 (file)
@@ -4596,10 +4596,15 @@ ListVLDB(struct cmd_syndesc *as, void *arock)
         */
        else if (centries > 0) {
            if (!tarray) {
-               /* steal away the first bulk entries array */
-               tarray = (struct uvldbentry *)arrayEntries.ubulkentries_val;
-               tarraysize = centries * sizeof(struct uvldbentry);
-               arrayEntries.ubulkentries_val = 0;
+               /* malloc the first bulk entries array */
+                tarraysize = centries * sizeof(struct uvldbentry);
+                tarray = malloc(tarraysize);
+               if (!tarray) {
+                   fprintf(STDERR,
+                           "Could not allocate enough space for the VLDB entries\n");
+                   goto bypass;
+               }
+                memcpy((char*)tarray, arrayEntries.ubulkentries_val, tarraysize);
            } else {
                /* Grow the tarray to keep the extra entries */
                parraysize = (centries * sizeof(struct uvldbentry));