From 4a4493c72039cd4457851ddcbb23367c6a7556ae Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 11 Jan 2009 06:11:41 +0000 Subject: [PATCH] STABLE14-viced-callback-20090110 LICENSE MIT FIXES 124099 CB and FE point to one before the array. Decrement them as needed after the valid allocation check. --- src/viced/callback.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/viced/callback.c b/src/viced/callback.c index 4ba3c41bd..c6e9f0c55 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -532,19 +532,21 @@ InitCallBack(int nblks) tfirst = CBtime(FT_ApproxTime()); /* N.B. The "-1", below, is because * FE[0] and CB[0] are not used--and not allocated */ - FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry)))) - 1; + FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry)))); if (!FE) { ViceLog(0, ("Failed malloc in InitCallBack\n")); assert(0); } + FE--; /* FE[0] is supposed to point to junk */ cbstuff.nFEs = nblks; while (cbstuff.nFEs) FreeFE(&FE[cbstuff.nFEs]); /* This is correct */ - CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack)))) - 1; + CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack)))); if (!CB) { ViceLog(0, ("Failed malloc in InitCallBack\n")); assert(0); } + CB--; /* CB[0] is supposed to point to junk */ cbstuff.nCBs = nblks; while (cbstuff.nCBs) FreeCB(&CB[cbstuff.nCBs]); /* This is correct */ -- 2.39.5