| 1776 | } |
| 1777 | |
| 1778 | static void |
| 1779 | parse_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 |
no test coverage detected