From b2d92ab17dcfae6058a808fc47227969aab0a246 Mon Sep 17 00:00:00 2001 From: Rainer Toebbicke Date: Thu, 17 May 2007 06:47:06 +0000 Subject: [PATCH] STABLE14-bucoord-dump-levels-20070517 FIXES 57246 dont use memory past what you've allocated (cherry picked from commit 87a93241dab68696a54c8e43df4ffb70928fce21) --- src/bucoord/restore.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bucoord/restore.c b/src/bucoord/restore.c index 24a3042141..bbecd9124f 100644 --- a/src/bucoord/restore.c +++ b/src/bucoord/restore.c @@ -40,7 +40,6 @@ RCSID extern struct bc_dumpTask bc_dumpTasks[BC_MAXSIMDUMPS]; extern char *whoami; -#define BC_MAXLEVELS 20 #define MAXTAPESATONCE 10 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr @@ -182,9 +181,10 @@ bc_Restorer(aindex) statusP statusPtr, newStatusPtr; struct dumpinfo *dumpinfolist = NULL; - struct dumpinfo *pdi, *ndi, *di, dlevels[BC_MAXLEVELS]; + struct dumpinfo *pdi, *ndi, *di, *dlevels; struct volinfo *pvi, *nvi, *vi; afs_int32 lvl, lv; + int num_dlevels = 20; afs_int32 serverAll; /* The server to which all volumes are to be restore to */ afs_int32 partitionAll; /* Likewise for partition */ @@ -196,6 +196,8 @@ bc_Restorer(aindex) extern statusP createStatusNode(); extern statusP findStatus(); + dlevels = (struct dumpinfo *) malloc(num_dlevels * sizeof(*dlevels)); + dumpTaskPtr = &bc_dumpTasks[aindex]; serverAll = HOSTADDR(&dumpTaskPtr->destServer); partitionAll = dumpTaskPtr->destPartition; @@ -314,6 +316,14 @@ bc_Restorer(aindex) memcpy(&dlevels[0], di, sizeof(struct dumpinfo)); for (lvl = 1, parent = dlevels[0].parentDumpId; parent; parent = dlevels[lvl].parentDumpId, lvl++) { + if (lvl >= num_dlevels) { /* running out of dump levels */ + struct dumpinfo *tdl = dlevels; + + num_dlevels += num_dlevels; /* double */ + dlevels = (struct dumpinfo *) malloc(num_dlevels * sizeof(*dlevels)); + memcpy(dlevels, tdl, (num_dlevels/2) * sizeof(*dlevels)); + free(tdl); + } code = bcdb_FindDumpByID(parent, &dumpDescr1); if (code) { for (vi = di->volinfolist; vi; vi = vi->next) { @@ -768,5 +778,7 @@ bc_Restorer(aindex) if (volumeEntries) free(volumeEntries); + free(dlevels); + return code; }