[git commit] chattr: fix "chattr =ae -R FILE"

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 23 16:57:00 UTC 2021


commit: https://git.busybox.net/busybox/commit/?id=5709b51a75c6fe2cf6afcb2f5dcb9d227899f351
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

-R is not an "unset these flags" argument, thus no conflict with "=".

function                                             old     new   delta
.rodata                                           103684  103686      +2

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 e2fsprogs/chattr.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c
index b424e797b..1b12c9f37 100644
--- a/e2fsprogs/chattr.c
+++ b/e2fsprogs/chattr.c
@@ -85,7 +85,9 @@ static char** decode_arg(char **argv, struct globals *gp)
 
 	fl = &gp->af;
 	if (opt == '-') {
-		gp->flags |= OPT_REM;
+		/* gp->flags |= OPT_REM; - WRONG, it can be an option */
+		/* testcase: chattr =ae -R FILE should not complain "= is incompatible with - and +" */
+		/* (and should not read flags, with =FLAGS they can be just set directly) */
 		fl = &gp->rf;
 	} else if (opt == '+') {
 		gp->flags |= OPT_ADD;
@@ -115,7 +117,7 @@ static char** decode_arg(char **argv, struct globals *gp)
 			if (*arg == 'v') {
 				if (!*++argv)
 					bb_show_usage();
-				gp->version = xatoul(*argv);
+				gp->version = xatou(*argv);
 				gp->flags |= OPT_SET_VER;
 				continue;
 			}
@@ -127,8 +129,9 @@ static char** decode_arg(char **argv, struct globals *gp)
 				continue;
 			}
 			/* not a known option, try as an attribute */
+			gp->flags |= OPT_REM;
 		}
-		*fl |= get_flag(*arg);
+		*fl |= get_flag(*arg); /* aborts on bad flag letter */
 	}
 
 	return argv;
@@ -241,7 +244,7 @@ int chattr_main(int argc UNUSED_PARAM, char **argv)
 	if (g.rf & g.af)
 		bb_simple_error_msg_and_die("can't set and unset a flag");
 	if (!g.flags)
-		bb_simple_error_msg_and_die("must use '-v', =, - or +");
+		bb_simple_error_msg_and_die("must use -v, -p, =, - or +");
 
 	/* now run chattr on all the files passed to us */
 	do change_attributes(*argv, &g); while (*++argv);


More information about the busybox-cvs mailing list