* Re: [LTP] [PATCH 2/2] lib: Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF
@ 2022-12-01 2:59 zhaogongyi via ltp
0 siblings, 0 replies; 3+ messages in thread
From: zhaogongyi via ltp @ 2022-12-01 2:59 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
>
> On Wed, Nov 30, 2022 at 10:19:01AM +0800, Zhao Gongyi via ltp wrote:
> > Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF in parse_opts(), it is
> > hoped to deal with the abnormal input.
> >
> > Modify the requirement iterations range from '>= 0' to '> 0', when
> > iterations' value equal to 0, the test will not run.
> >
> > Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> > ---
> > lib/tst_test.c | 8 +++-----
> > 1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/lib/tst_test.c b/lib/tst_test.c index
> > b62559d75..254229d96 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -677,15 +677,13 @@ static void parse_opts(int argc, char *argv[])
> > print_test_tags();
> > exit(0);
> > case 'i':
> > - iterations = atoi(optarg);
> > - if (iterations < 0)
> > - tst_brk(TBROK, "Number of iterations (-i) must be >=
> 0");
> > + iterations = SAFE_STRTOL(optarg, 1, INT_MAX);
> > break;
> > case 'I':
> > if (tst_test->max_runtime > 0)
> > - tst_test->max_runtime = atoi(optarg);
> > + tst_test->max_runtime = SAFE_STRTOL(optarg, 1,
> INT_MAX);
> > else
> > - duration = atof(optarg);
> > + duration = SAFE_STRTOF(optarg);
>
> Shouldn't we limit the duration to positive numbers here as well?
>
> I guess that we should add min and max option to the SAFE_STRTOF() and
> call the conversion with SAFE_STRTOF(optarg, 0.1, HUGE_VALF); here
> instead.
Agree, it is better to add range checking for SAFE_STRTOF, I have resubmit a new patch to fix it, please see: https://patchwork.ozlabs.org/project/ltp/patch/20221201025141.71227-3-zhaogongyi@huawei.com/
Regards,
Gongyi
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH 2/2] lib: Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF
2022-11-30 2:19 ` [LTP] [PATCH 2/2] lib: Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF Zhao Gongyi via ltp
@ 2022-11-30 13:49 ` Cyril Hrubis
0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2022-11-30 13:49 UTC (permalink / raw)
To: Zhao Gongyi; +Cc: ltp
On Wed, Nov 30, 2022 at 10:19:01AM +0800, Zhao Gongyi via ltp wrote:
> Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF in parse_opts(),
> it is hoped to deal with the abnormal input.
>
> Modify the requirement iterations range from '>= 0' to '> 0',
> when iterations' value equal to 0, the test will not run.
>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
> lib/tst_test.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index b62559d75..254229d96 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -677,15 +677,13 @@ static void parse_opts(int argc, char *argv[])
> print_test_tags();
> exit(0);
> case 'i':
> - iterations = atoi(optarg);
> - if (iterations < 0)
> - tst_brk(TBROK, "Number of iterations (-i) must be >= 0");
> + iterations = SAFE_STRTOL(optarg, 1, INT_MAX);
> break;
> case 'I':
> if (tst_test->max_runtime > 0)
> - tst_test->max_runtime = atoi(optarg);
> + tst_test->max_runtime = SAFE_STRTOL(optarg, 1, INT_MAX);
> else
> - duration = atof(optarg);
> + duration = SAFE_STRTOF(optarg);
Shouldn't we limit the duration to positive numbers here as well?
I guess that we should add min and max option to the SAFE_STRTOF() and
call the conversion with SAFE_STRTOF(optarg, 0.1, HUGE_VALF); here
instead.
> break;
> case 'C':
> #ifdef UCLINUX
> --
> 2.17.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH 2/2] lib: Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF
2022-11-30 2:18 [LTP] [PATCH 0/2] Add handling of abnormal input for parse_opts() Zhao Gongyi via ltp
@ 2022-11-30 2:19 ` Zhao Gongyi via ltp
2022-11-30 13:49 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Zhao Gongyi via ltp @ 2022-11-30 2:19 UTC (permalink / raw)
To: ltp
Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF in parse_opts(),
it is hoped to deal with the abnormal input.
Modify the requirement iterations range from '>= 0' to '> 0',
when iterations' value equal to 0, the test will not run.
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
lib/tst_test.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index b62559d75..254229d96 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -677,15 +677,13 @@ static void parse_opts(int argc, char *argv[])
print_test_tags();
exit(0);
case 'i':
- iterations = atoi(optarg);
- if (iterations < 0)
- tst_brk(TBROK, "Number of iterations (-i) must be >= 0");
+ iterations = SAFE_STRTOL(optarg, 1, INT_MAX);
break;
case 'I':
if (tst_test->max_runtime > 0)
- tst_test->max_runtime = atoi(optarg);
+ tst_test->max_runtime = SAFE_STRTOL(optarg, 1, INT_MAX);
else
- duration = atof(optarg);
+ duration = SAFE_STRTOF(optarg);
break;
case 'C':
#ifdef UCLINUX
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-01 2:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 2:59 [LTP] [PATCH 2/2] lib: Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF zhaogongyi via ltp
-- strict thread matches above, loose matches on Subject: below --
2022-11-30 2:18 [LTP] [PATCH 0/2] Add handling of abnormal input for parse_opts() Zhao Gongyi via ltp
2022-11-30 2:19 ` [LTP] [PATCH 2/2] lib: Replace atoi/atof with SAFE_STRTOL/SAFE_STRTOF Zhao Gongyi via ltp
2022-11-30 13:49 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.