lkml.org 
[lkml]   [2013]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] fs/befs/linuxvfs.c: need signed cast for variable 'block'
From
On Wed, Oct 30, 2013 at 7:52 PM, Chen Gang <gang.chen@asianux.com> wrote:
> Need signed cast for it, the original author assume the type of 'block'
> is long, so just cast to long. The related warnings (with allmodconfig):
>
> fs/befs/linuxvfs.c:136:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> fs/befs/linuxvfs.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
> index daa15d6..27e5179 100644
> --- a/fs/befs/linuxvfs.c
> +++ b/fs/befs/linuxvfs.c
> @@ -133,7 +133,7 @@ befs_get_block(struct inode *inode, sector_t block,
> befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld",
> inode->i_ino, block);
>
> - if (block < 0) {
> + if ((long)block < 0) {
> befs_error(sb, "befs_get_block() was asked for a block "
> "number less than zero: block %ld in inode %lu",
> block, inode->i_ino);

If block (type sector_t) is unsigned, we shouldn't cast it signed.
This entire code path should be removed. What is BEFS's expected
maximum block size? (Looks like even befs_blocknr_t is u64, so nothing
seems trivially in danger of wrapping.) I would also note that all the
format strings are wrong too (%ld instead of %lu).

-Kees

--
Kees Cook
Chrome OS Security


\
 
 \ /
  Last update: 2013-10-31 18:01    [W:0.064 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site