MCPcopy Create free account
hub / github.com/containers/bubblewrap / parse_args_recurse

Function parse_args_recurse

bubblewrap.c:1778–2792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1776}
1777
1778static void
1779parse_args_recurse (int *argcp,
1780 const char ***argvp,
1781 bool in_file,
1782 int *total_parsed_argc_p)
1783{
1784 SetupOp *op;
1785 int argc = *argcp;
1786 const char **argv = *argvp;
1787 /* I can't imagine a case where someone wants more than this.
1788 * If you do...you should be able to pass multiple files
1789 * via a single tmpfs and linking them there, etc.
1790 *
1791 * We're adding this hardening due to precedent from
1792 * http://googleprojectzero.blogspot.com/2014/08/the-poisoned-nul-byte-2014-edition.html
1793 *
1794 * I picked 9000 because the Internet told me to and it was hard to
1795 * resist.
1796 */
1797 static const int32_t MAX_ARGS = 9000;
1798
1799 if (*total_parsed_argc_p > MAX_ARGS)
1800 die ("Exceeded maximum number of arguments %u", MAX_ARGS);
1801
1802 while (argc > 0)
1803 {
1804 const char *arg = argv[0];
1805
1806 if (strcmp (arg, "--help") == 0)
1807 {
1808 usage (EXIT_SUCCESS, stdout);
1809 }
1810 else if (strcmp (arg, "--version") == 0)
1811 {
1812 print_version_and_exit ();
1813 }
1814 else if (strcmp (arg, "--args") == 0)
1815 {
1816 int the_fd;
1817 char *endptr;
1818 const char *p, *data_end;
1819 size_t data_len;
1820 cleanup_free const char **data_argv = NULL;
1821 const char **data_argv_copy;
1822 int data_argc;
1823 int i;
1824
1825 if (in_file)
1826 die ("--args not supported in arguments file");
1827
1828 if (argc < 2)
1829 die ("--args takes an argument");
1830
1831 the_fd = strtol (argv[1], &endptr, 10);
1832 if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
1833 die ("Invalid fd: %s", argv[1]);
1834
1835 /* opt_args_data is essentially a recursive argv array, which we must

Callers 1

parse_argsFunction · 0.85

Calls 15

dieFunction · 0.85
usageFunction · 0.85
print_version_and_exitFunction · 0.85
load_file_dataFunction · 0.85
die_with_errorFunction · 0.85
xcallocFunction · 0.85
warn_only_last_optionFunction · 0.85
setup_op_newFunction · 0.85
xasprintfFunction · 0.85
die_unless_label_validFunction · 0.85
label_create_fileFunction · 0.85

Tested by

no test coverage detected