From: Lennart Poettering Date: Fri, 14 Mar 2025 10:43:07 +0000 (+0100) Subject: udevadm: check number of passed arguments X-Git-Tag: v257.5~106 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=81b821d08ceb5feec4b879d59c194897a957eb5e;p=thirdparty%2Fsystemd.git udevadm: check number of passed arguments We didn't check the number of arguments first, hence ended up outputting some ugly complaints with `(null)` in a format string. And what's worse accepted any number of arguments, where we'd ignore all but the first two though. (cherry picked from commit e5dfe2cd8d32c3ddd3ca6763dbbe2d0ea2ab61aa) --- diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 5815f2cc781..9437a3a0080 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -60,16 +60,11 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached(); } - arg_command = argv[optind++]; - if (!arg_command) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Command missing."); - - arg_syspath = argv[optind++]; - if (!arg_syspath) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "device is missing."); + if (argc != optind + 2) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Expected two arguments: command string and device path."); + arg_command = ASSERT_PTR(argv[optind]); + arg_syspath = ASSERT_PTR(argv[optind+1]); return 1; }