STABLE14-bucoord-dump-levels-20070517

FIXES 57246

dont use memory past what you've allocated


(cherry picked from commit 87a93241dab68696a54c8e43df4ffb70928fce21)
This commit is contained in:
Rainer Toebbicke 2007-05-17 06:47:06 +00:00 committed by Derrick Brashear
parent 1b5eba2c4f
commit b2d92ab17d

View File

@ -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;
}