viced: Assert valid statistics indices
authorAndrew Deason <adeason@sinenomine.net>
Thu, 29 Sep 2011 23:36:07 +0000 (18:36 -0500)
committerDerrick Brashear <shadow@dementix.org>
Fri, 30 Sep 2011 23:50:59 +0000 (16:50 -0700)
Make sure we are passed valid statistic index numbers, so passing in a
bad index doesn't result in writing over random memory.

Change-Id: I29ed03b59df937e6f95fba44209a03db23613a8d
Reviewed-on: http://gerrit.openafs.org/5525
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

src/viced/fsstats.c

index ec933b9..efaeb38 100644 (file)
@@ -12,6 +12,7 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <assert.h>
 #include <roken.h>
 
 #include <afs/afsint.h>
@@ -25,6 +26,7 @@
 void
 fsstats_StartOp(struct fsstats *stats, int index)
 {
+    assert(index >= 0 && index < FS_STATS_NUM_RPC_OPS);
     stats->opP = &(afs_FullPerfStats.det.rpcOpTimes[index]);
     FS_LOCK;
     (stats->opP->numOps)++;
@@ -57,6 +59,7 @@ fsstats_FinishOp(struct fsstats *stats, int code)
 void
 fsstats_StartXfer(struct fsstats *stats, int index)
 {
+    assert(index >= 0 && index < FS_STATS_NUM_XFER_OPS);
     FT_GetTimeOfDay(&stats->xferStartTime, NULL);
     stats->xferP = &(afs_FullPerfStats.det.xferOpTimes[index]);
 }