break;
}
}
- argv += optind;
- /* argc -= optind; - no need, argc is not used below */
- acolumn_spaces = xmalloc(acolumn + 1);
- memset(acolumn_spaces, ' ', acolumn);
- acolumn_spaces[acolumn] = '\0';
+ argv += optind;
+ argc -= optind;
- if (!argv[0] && !nprocs) {
+ if (argc < 0 || (!argv[0] && !nprocs)) {
error_msg_and_help("must have PROG [ARGS] or -p PID");
}
tflag = 1;
}
+ acolumn_spaces = xmalloc(acolumn + 1);
+ memset(acolumn_spaces, ' ', acolumn);
+ acolumn_spaces[acolumn] = '\0';
+
sigprocmask(SIG_SETMASK, NULL, &start_set);
memcpy(&blocked_set, &start_set, sizeof(blocked_set));
check_h "invalid -s argument: '1073741824'" -s 1073741824
check_h "invalid -I argument: '5'" -I 5
+cat > "$EXP" << '__EOF__'
+strace: must have PROG [ARGS] or -p PID
+Try 'strace -h' for more information.
+__EOF__
+../zeroargc "$strace_exp" /bin/true 2> "$LOG" &&
+ dump_log_and_fail_with \
+ 'zeroargc strace failed to handle the error properly'
+match_diff "$LOG" "$EXP" ||
+ dump_log_and_fail_with \
+ 'zeroargc strace failed to print expected diagnostics'
+
if [ -n "${UID-}" ]; then
if [ "${UID-}" = 0 ]; then
umsg="Cannot find user ':nosuchuser:'"
--- /dev/null
+/*
+ * Execute an executable with zero argc and specified anvironment.
+ *
+ * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(const int ac, char **const av)
+{
+ if (ac < 2)
+ error_msg_and_fail("missing operand");
+ const char *const path = av[1];
+ av[1] = 0;
+ execve(path, av + 1, av + 2);
+ perror_msg_and_fail("execve: %s", path);
+}