Comment 0 for bug 1198535

Revision history for this message
Hubert (y-launchpad-acc372445) wrote :

In the portion of code copied below from mhddfs/main.c, version 0.1.38, the function mhdd_statfs does
 stats = calloc(mhdd.cdirs, sizeof(struct statvfs));
and it should do
 stats = calloc(mhdd.cdirs, mhdd.cdirs*sizeof(struct statvfs));
because they are used as arrays with stats[i] and devices[i]

I'm not 100% sure about this being an actual error, and I'm guessing this may be working with some compilers or in some circumstances, yet I think this:
  int ret = statvfs(mhdd.dirs[i], stats+i); //HERE
should be replaced by this:
  int ret = statvfs(mhdd.dirs[i], stats+i); //HERE

Here is the portion of code,

static int mhdd_statfs(const char *path, struct statvfs *buf)
{
 int i, j;
 struct statvfs * stats;
 struct stat st;
 dev_t * devices;

 mhdd_debug(MHDD_MSG, "mhdd_statfs: %s\n", path);

 stats = calloc(mhdd.cdirs, sizeof(struct statvfs)); // HERE
 devices = calloc(mhdd.cdirs, sizeof(dev_t)); //HERE

 for (i = 0; i < mhdd.cdirs; i++) {
  int ret = statvfs(mhdd.dirs[i], stats+i); //HERE
  if (ret != 0) {
   free(stats);
   free(devices);
   return -errno;
  }

  ret = stat(mhdd.dirs[i], &st);
  if (ret != 0) {
   free(stats);
   free(devices);
   return -errno;
  }
  devices[i] = st.st_dev;
 }

 unsigned long
  min_block = stats[0].f_bsize,
  min_frame = stats[0].f_frsize;

 for (i = 1; i<mhdd.cdirs; i++) {
  if (min_block>stats[i].f_bsize) min_block = stats[i].f_bsize;
  if (min_frame>stats[i].f_frsize) min_frame = stats[i].f_frsize;
 }
...
}

/*
   mhddfs - Multi HDD [FUSE] File System
   Copyright (C) 2008 Dmitry E. Oboukhov <email address hidden>
...
   Modified by Glenn Washburn <email address hidden>
    (added support for extended attributes.)
*/