From 8137beb265a9b763d75672d7a5fd9c0c3fb3d0c9 Mon Sep 17 00:00:00 2001 From: Steve Beattie Date: Mon, 27 Sep 2021 11:53:16 -0700 Subject: [PATCH 1/2] binutils/aa-features-abi: make -f short arg actually be accepted The aa-features-abi -f short argument was not added to the getopt_long() set of short arguments, resulting in the command incorrectly failing like so: $ ./aa-features-abi -f /etc/apparmor.d/abi/3.0 ./aa-features-abi: invalid option -- 'f' USAGE: ./aa-features-abi [OPTIONS] [OUTPUT OPTIONS] [...] The long --file option works as expected. Fix this by adding f to the set of short arguments passed to getopt_long(). Signed-off-by: Steve Beattie Acked-by: John Johansen MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/804 --- binutils/aa_features_abi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binutils/aa_features_abi.c b/binutils/aa_features_abi.c index a92574466..8885b6a52 100644 --- a/binutils/aa_features_abi.c +++ b/binutils/aa_features_abi.c @@ -124,7 +124,7 @@ static char **parse_args(int argc, char **argv) {"stdout", no_argument, 0, ARG_STDOUT}, }; - while ((opt = getopt_long(argc, argv, "+dvhxl:w:", long_opts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "+dvhxf:l:w:", long_opts, NULL)) != -1) { switch (opt) { case 'd': opt_debug = true; From ffc6529bef6b799795bbb6fb9bcb4590a25e5f4e Mon Sep 17 00:00:00 2001 From: Steve Beattie Date: Mon, 27 Sep 2021 12:12:33 -0700 Subject: [PATCH 2/2] binutils/aa-features-abi: fix failure to close fd due to shadowed var decl The variable used to store the file descriptor for the --file ended up being declared twice, resulting in the autoclose attribute attached to the first declaration being removed by the shadowed second declaration. Fix this by converting the second declaration to just be an assignment, as was intended. strace output before: [...] ) = 1925 close(1) = 0 exit_group(0) = ? +++ exited with 0 +++ strace output after removing shadow declaration: ) = 1925 close(1) = 0 close(3) = 0 exit_group(0) = ? +++ exited with 0 +++ (File descriptor 3 is what is returned by the open() call on the --file argument.) Signed-off-by: Steve Beattie Acked-by: John Johansen MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/804 --- binutils/aa_features_abi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binutils/aa_features_abi.c b/binutils/aa_features_abi.c index 8885b6a52..ed734aea9 100644 --- a/binutils/aa_features_abi.c +++ b/binutils/aa_features_abi.c @@ -181,7 +181,7 @@ int main(int argc, char **argv) error("failed to extract features abi from the kernel"); } if (opt_file) { - int in = open(opt_file, O_RDONLY); + in = open(opt_file, O_RDONLY); if (in == -1) error("failed to open file '%s'", opt_file); rc = aa_features_new_from_file(&features, in);