From: Dmitry Safonov <0x7f454c46@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-kselftest@vger.kernel.org
Subject: Re: [bug report] selftest/net/xfrm: Add test for ipsec tunnel
Date: Tue, 19 Jul 2022 20:42:27 +0100 [thread overview]
Message-ID: <5355cf8c-96fd-f667-3352-29411c2c0e27@gmail.com> (raw)
In-Reply-To: <Yta1LXmj5e4CPmNA@kili>
On 7/19/22 14:44, Dan Carpenter wrote:
> Hello Dmitry Safonov,
>
> The patch bc2652b7ae1e: "selftest/net/xfrm: Add test for ipsec
> tunnel" from Sep 21, 2020, leads to the following Smatch static
> checker warning:
>
> tools/testing/selftests/net/ipsec.c:2294 main()
> warn: impossible condition '(nr_process == 9223372036854775807) => (0-4294967295 == s64max)'
>
> tools/testing/selftests/net/ipsec.c
> 2278 int main(int argc, char **argv)
> 2279 {
> 2280 unsigned int nr_process = 1;
> 2281 int route_sock = -1, ret = KSFT_SKIP;
> 2282 int test_desc_fd[2];
> 2283 uint32_t route_seq;
> 2284 unsigned int i;
> 2285
> 2286 if (argc > 2)
> 2287 exit_usage(argv);
> 2288
> 2289 if (argc > 1) {
> 2290 char *endptr;
> 2291
> 2292 errno = 0;
> 2293 nr_process = strtol(argv[1], &endptr, 10);
> --> 2294 if ((errno == ERANGE && (nr_process == LONG_MAX || nr_process == LONG_MIN))
>
> nr_process is a u32 so it can't be LONG_MIN/MAX. Do we even need to test
> this or could we just fall through to the the > MAX_PROCESSES warning?
I would think it's still needed to check parsing underflow/overflow.
But comparing u32 to LONG_MIN/LONG_MAX clearly doesn't make sense.
I think, I did it as the man strtol told, without thinking twice about
the type:
> The strtol() function returns the result of the conversion, unless
> the value would underflow or overflow. If an underflow occurs,
> strtol() returns LONG_MIN. If an overflow occurs, strtol() returns
> LONG_MAX. In both cases, errno is set to ERANGE.
I think the check of errno == ERANGE can stand without checks for
LONG_MIN/LONG_MAX.
>
> 2295 || (errno != 0 && nr_process == 0)
> 2296 || (endptr == argv[1]) || (*endptr != '\0')) {
> 2297 printk("Failed to parse [nr_process]");
> 2298 exit_usage(argv);
> 2299 }
> 2300
> 2301 if (nr_process > MAX_PROCESSES || !nr_process) {
> 2302 printk("nr_process should be between [1; %u]",
> 2303 MAX_PROCESSES);
> 2304 exit_usage(argv);
> 2305 }
> 2306 }
> 2307
>
> regards,
> dan carpenter
Thanks,
Dmitry
prev parent reply other threads:[~2022-07-19 19:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 13:44 [bug report] selftest/net/xfrm: Add test for ipsec tunnel Dan Carpenter
2022-07-19 19:42 ` Dmitry Safonov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5355cf8c-96fd-f667-3352-29411c2c0e27@gmail.com \
--to=0x7f454c46@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-kselftest@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox