From: Jeffrey Altman Date: Tue, 28 Dec 2010 00:34:14 +0000 (-0500) Subject: vos: do not mix memory allocation methods X-Git-Tag: upstream/1.6.0.pre2^2~97 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=a3a7fb4fd617aaa1bd372bc2929caa9d01987cc6;p=packages%2Fo%2Fopenafs.git vos: do not mix memory allocation methods 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 Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman (cherry picked from commit 463b045b9fe4a412877c2a65f5deafb1442c1bf1) Change-Id: I64f43459a212ceb1b4f89e45a9827fc7b981ff6e Reviewed-on: http://gerrit.openafs.org/3807 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/volser/vos.c b/src/volser/vos.c index 2c55983c3..8d06d82e4 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -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));