chattr: add maximum value check for project
PATCH 1/1 chattr: add maximum value check for project
From: Wang Shilong <[email protected]>
See following output:
[root@mds03 client]# chattr -R +P -p 4294967296 testdir/ [root@mds03 client]# lsattr -dp testdir/
0 ----------------P testdir/
[root@mds03 client]# chattr -R +P -p 4294967297 testdir/
[root@mds03 client]# lsattr -dp testdir/
1 ----------------P testdir/Reported-by Shuichi Ihara <[email protected]>
Signed-off-by Wang Shilong <[email protected]>
--- lib/ext2fs/ext2_fs.h | 2 ++ misc/chattr.c | 11 ++++++++--- misc/mke2fs.c | 2 -- 3 files changed, 10 insertions(+), 5 deletions(-)
lib/ext2fs/ext2_fs.h +2 -0
@@ -75,6 +75,8 @@*/ #define EXT2_LINK_MAX 65000 +#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1) +/* * Macro-instructions used to manage several block sizes */
misc/chattr.c +8 -3
@@ -152,13 +152,18 @@ static int decode_arg (int * i, int argc, char ** argv)if (*p =='p' ) { (*i)++;if (*i >= argc) -usage (); - project =strtol (argv[*i], &tmp,0 ); +usage (); + project =strtol (argv[*i], &tmp,0 );if (*tmp) {com_err (program_name,0 ,_ ("bad project - %s\n" ), argv[*i]); -usage (); +usage (); + } +if (project >MAX_32_NUM ) { +com_err (program_name,0 , +_ ("Kernel does not support set project ID this large" )); +exit (1 ); } set_project =1 ;continue ;
misc/mke2fs.c +0 -1
@@ -63,8 +63,6 @@ extern int optind;#define STRIDE_LENGTH 8 -#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
Quoted 23 lines · Wang Shilong
From: Wang Shilong <[email protected]>
See following output:
[root@mds03 client]# chattr -R +P -p 4294967296 testdir/ [root@mds03 client]# lsattr -dp testdir/0 ----------------P testdir/ [root@mds03 client]# chattr -R +P -p 4294967297 testdir/ [root@mds03 client]# lsattr -dp testdir/ 1 ----------------P testdir/Reported-by Shuichi Ihara <[email protected]>Signed-off-by Wang Shilong <[email protected]>--- lib/ext2fs/ext2_fs.h | 2 ++ misc/chattr.c | 11 ++++++++--- misc/mke2fs.c | 2 -- 3 files changed, 10 insertions(+), 5 deletions(-)lib/ext2fs/ext2_fs.h +0
-0
lib/ext2fs/ext2_fs.h line 78
Quoted 4 lines
lib/ext2fs/ext2_fs.h +1
-0@@ -75,6 +75,8 @@*/ #define EXT2_LINK_MAX 65000 +#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
Is UINT32_MAX insufficient for these uses?
Also, this whole section of decode_arg mixes types... project is 'unsigned long', MAX_32_NUM is 'unsigned long long', and strtol returns 'long'. Can we pick one and stick with it?
--D
Quoted 46 lines
lib/ext2fs/ext2_fs.h +1
-0+/* * Macro-instructions used to manage several block sizes */ misc/chattr.c +8
-3@@ -152,13 +152,18 @@ static int decode_arg (int * i, int argc, char ** argv)if (*p =='p' ) { (*i)++;if (*i >= argc) -usage (); - project =strtol (argv[*i], &tmp,0 ); +usage (); + project =strtol (argv[*i], &tmp,0 );if (*tmp) {com_err (program_name,0 ,_ ("bad project - %s\n" ), argv[*i]); -usage (); +usage (); + } +if (project >MAX_32_NUM ) { +com_err (program_name,0 , +_ ("Kernel does not support set project ID this large" )); +exit (1 ); } set_project =1 ;continue ;misc/mke2fs.c +0
-2@@ -63,8 +63,6 @@ extern int optind;#define STRIDE_LENGTH 8 -#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1) -#ifndef __sparc__#define ZAP_BOOTBLOCK #endif Signature · 1 line
1.8.3.1