From: Thomas Veerman Date: Thu, 26 Jul 2012 15:16:11 +0000 (+0000) Subject: MFS: fixes for defects reported by Coverity X-Git-Tag: v3.2.1~436 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=1c480f749a40ccab164347a5b8287f334197f5e2;p=minix.git MFS: fixes for defects reported by Coverity .use safe string copy .fix (potential) int overflow in function return --- diff --git a/servers/mfs/path.c b/servers/mfs/path.c index 73a080aff..31a49c80b 100644 --- a/servers/mfs/path.c +++ b/servers/mfs/path.c @@ -450,7 +450,7 @@ char string[MFS_NAME_MAX+1]; /* component extracted from 'old_name' */ /* Special case of the string at cp is empty */ if (len == 0) - strcpy(string, "."); /* Return "." */ + strlcpy(string, ".", MFS_NAME_MAX + 1); /* Return "." */ else { memcpy(string, cp, len); string[len]= '\0'; diff --git a/servers/mfs/stadir.c b/servers/mfs/stadir.c index 24ec94e2a..5fc84ded0 100644 --- a/servers/mfs/stadir.c +++ b/servers/mfs/stadir.c @@ -18,7 +18,8 @@ static blkcnt_t estimate_blocks(struct inode *rip) * indirect blocks is too costly for a stat call, so we disregard holes and * return a conservative estimation. */ - unsigned int zone_size, zones, sindirs, dindirs, nr_indirs, sq_indirs; + unsigned int zone_size, zones; + blkcnt_t sindirs, dindirs, nr_indirs, sq_indirs; /* Compute the number of zones used by the file. */ zone_size = rip->i_sp->s_block_size << rip->i_sp->s_log_zone_size; @@ -26,16 +27,16 @@ static blkcnt_t estimate_blocks(struct inode *rip) zones = (rip->i_size + zone_size - 1) / zone_size; /* Compute the number of indirect blocks needed for that zone count. */ - nr_indirs = rip->i_nindirs; + nr_indirs = (blkcnt_t) rip->i_nindirs; sq_indirs = nr_indirs * nr_indirs; - sindirs = (zones - rip->i_ndzones + nr_indirs - 1) / nr_indirs; - dindirs = (sindirs - 1 + sq_indirs - 1) / sq_indirs; + sindirs = (blkcnt_t) (zones - rip->i_ndzones + nr_indirs - 1) / nr_indirs; + dindirs = (blkcnt_t) (sindirs - 1 + sq_indirs - 1) / sq_indirs; /* Return the number of 512-byte blocks corresponding to the number of data * zones and indirect blocks. */ - return (zones + sindirs + dindirs) * (zone_size / 512); + return((blkcnt_t) (zones + sindirs + dindirs) * (zone_size / 512)); } /*===========================================================================*