summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2021-10-11 09:55:51 +0200
committerGitHub <noreply@github.com>2021-10-11 09:55:51 +0200
commit235856771e399fde585d1da57846fec39ab08215 (patch)
tree3fd904cfa88497a0d51aa3f67177c2128fc16992
parent47fa284aba23bc28adb3c40ac8f2072dbb581293 (diff)
parent0d369cdfd9b2feb9d8384cef46643831c4f252dd (diff)
downloadbubblewrap-235856771e399fde585d1da57846fec39ab08215.tar.gz
Merge pull request #457 from smcv/warn-on-nonrepeatable
Warn when non-repeatable options are repeated
-rw-r--r--bubblewrap.c53
-rw-r--r--utils.c24
-rw-r--r--utils.h2
3 files changed, 74 insertions, 5 deletions
diff --git a/bubblewrap.c b/bubblewrap.c
index 2e13fd0..e9c163d 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -1537,6 +1537,12 @@ takes_perms (const char *next_option)
}
static void
+warn_only_last_option (const char *name)
+{
+ warn ("Only the last %s option will take effect", name);
+}
+
+static void
parse_args_recurse (int *argcp,
const char ***argvp,
bool in_file,
@@ -1693,6 +1699,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--chdir takes one argument");
+ if (opt_chdir_path != NULL)
+ warn_only_last_option ("--chdir");
+
opt_chdir_path = argv[1];
argv++;
argc--;
@@ -1768,6 +1777,10 @@ parse_args_recurse (int *argcp,
{
if (argc < 2)
die ("--exec-label takes an argument");
+
+ if (opt_exec_label != NULL)
+ warn_only_last_option ("--exec-label");
+
opt_exec_label = argv[1];
die_unless_label_valid (opt_exec_label);
@@ -1778,6 +1791,10 @@ parse_args_recurse (int *argcp,
{
if (argc < 2)
die ("--file-label takes an argument");
+
+ if (opt_file_label != NULL)
+ warn_only_last_option ("--file-label");
+
opt_file_label = argv[1];
die_unless_label_valid (opt_file_label);
if (label_create_file (opt_file_label))
@@ -1957,6 +1974,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--sync-fd takes an argument");
+ if (opt_sync_fd != -1)
+ warn_only_last_option ("--sync-fd");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -1974,6 +1994,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--block-fd takes an argument");
+ if (opt_block_fd != -1)
+ warn_only_last_option ("--block-fd");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -1991,6 +2014,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--userns-block-fd takes an argument");
+ if (opt_userns_block_fd != -1)
+ warn_only_last_option ("--userns-block-fd");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2008,6 +2034,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--info-fd takes an argument");
+ if (opt_info_fd != -1)
+ warn_only_last_option ("--info-fd");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2025,6 +2054,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--json-status-fd takes an argument");
+ if (opt_json_status_fd != -1)
+ warn_only_last_option ("--json-status-fd");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2042,6 +2074,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--seccomp takes an argument");
+ if (opt_seccomp_fd != -1)
+ warn_only_last_option ("--seccomp");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2059,6 +2094,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--userns takes an argument");
+ if (opt_userns_fd != -1)
+ warn_only_last_option ("--userns");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2076,6 +2114,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--userns2 takes an argument");
+ if (opt_userns2_fd != -1)
+ warn_only_last_option ("--userns2");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2093,6 +2134,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--pidns takes an argument");
+ if (opt_pidns_fd != -1)
+ warn_only_last_option ("--pidns");
+
the_fd = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
die ("Invalid fd: %s", argv[1]);
@@ -2134,6 +2178,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--uid takes an argument");
+ if (opt_sandbox_uid != -1)
+ warn_only_last_option ("--uid");
+
the_uid = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_uid < 0)
die ("Invalid uid: %s", argv[1]);
@@ -2151,6 +2198,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--gid takes an argument");
+ if (opt_sandbox_gid != -1)
+ warn_only_last_option ("--gid");
+
the_gid = strtol (argv[1], &endptr, 10);
if (argv[1][0] == 0 || endptr[0] != 0 || the_gid < 0)
die ("Invalid gid: %s", argv[1]);
@@ -2165,6 +2215,9 @@ parse_args_recurse (int *argcp,
if (argc < 2)
die ("--hostname takes an argument");
+ if (opt_sandbox_hostname != NULL)
+ warn_only_last_option ("--hostname");
+
op = setup_op_new (SETUP_SET_HOSTNAME);
op->dest = argv[1];
op->flags = NO_CREATE_DEST;
diff --git a/utils.c b/utils.c
index 3753923..9901ea0 100644
--- a/utils.c
+++ b/utils.c
@@ -32,6 +32,24 @@
#define security_check_context(x) security_check_context ((security_context_t) x)
#endif
+__attribute__((format(printf, 1, 0))) static void
+warnv (const char *format, va_list args)
+{
+ fprintf (stderr, "bwrap: ");
+ vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+}
+
+void
+warn (const char *format, ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ warnv (format, args);
+ va_end (args);
+}
+
void
die_with_error (const char *format, ...)
{
@@ -56,14 +74,10 @@ die (const char *format, ...)
{
va_list args;
- fprintf (stderr, "bwrap: ");
-
va_start (args, format);
- vfprintf (stderr, format, args);
+ warnv (format, args);
va_end (args);
- fprintf (stderr, "\n");
-
exit (1);
}
diff --git a/utils.h b/utils.h
index 317d6d7..55a9585 100644
--- a/utils.h
+++ b/utils.h
@@ -48,6 +48,8 @@ typedef int bool;
#define PIPE_READ_END 0
#define PIPE_WRITE_END 1
+void warn (const char *format,
+ ...) __attribute__((format (printf, 1, 2)));
void die_with_error (const char *format,
...) __attribute__((__noreturn__)) __attribute__((format (printf, 1, 2)));
void die (const char *format,