* [PATCH] tools:iio: Fix the potential stack overflow risk
@ 2022-03-24 11:01 jianchunfu
2022-03-27 14:45 ` Jonathan Cameron
2022-03-27 22:12 ` Andy Shevchenko
0 siblings, 2 replies; 3+ messages in thread
From: jianchunfu @ 2022-03-24 11:01 UTC (permalink / raw)
To: jic23; +Cc: lars, linux-iio, jianchunfu
Add judgment to fix the potential stack overflow risk.
Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
---
tools/iio/iio_generic_buffer.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
index 2491c54a5..733fc21c2 100644
--- a/tools/iio/iio_generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -487,6 +487,10 @@ int main(int argc, char **argv)
return -ENOMEM;
}
trigger_name = malloc(IIO_MAX_NAME_LENGTH);
+ if (!trigger_name) {
+ ret = -ENOMEM;
+ goto error;
+ }
ret = read_sysfs_string("name", trig_dev_name, trigger_name);
free(trig_dev_name);
if (ret < 0) {
--
2.18.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tools:iio: Fix the potential stack overflow risk
2022-03-24 11:01 [PATCH] tools:iio: Fix the potential stack overflow risk jianchunfu
@ 2022-03-27 14:45 ` Jonathan Cameron
2022-03-27 22:12 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2022-03-27 14:45 UTC (permalink / raw)
To: jianchunfu; +Cc: lars, linux-iio
On Thu, 24 Mar 2022 19:01:57 +0800
jianchunfu <jianchunfu@cmss.chinamobile.com> wrote:
> Add judgment to fix the potential stack overflow risk.
>
> Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
Yikes.
Whilst it doesn't promise to be good code (it's meant to show
the principles, not for anyone to use it) the error handling
in this function is a mess :(
Whilst your change here looks good I think this function needs
a closer look so we fix them all together.
Just glancing at it, the decision on whether to go to the unified
error handling or return without doing anything seems entirely random.
If you want to take on a more general rework of the error handling
in that function it would be great. If not I 'might' get to it at
somepoint....
Thanks,
Jonathan
> ---
> tools/iio/iio_generic_buffer.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
> index 2491c54a5..733fc21c2 100644
> --- a/tools/iio/iio_generic_buffer.c
> +++ b/tools/iio/iio_generic_buffer.c
> @@ -487,6 +487,10 @@ int main(int argc, char **argv)
> return -ENOMEM;
> }
> trigger_name = malloc(IIO_MAX_NAME_LENGTH);
> + if (!trigger_name) {
> + ret = -ENOMEM;
> + goto error;
> + }
> ret = read_sysfs_string("name", trig_dev_name, trigger_name);
> free(trig_dev_name);
> if (ret < 0) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tools:iio: Fix the potential stack overflow risk
2022-03-24 11:01 [PATCH] tools:iio: Fix the potential stack overflow risk jianchunfu
2022-03-27 14:45 ` Jonathan Cameron
@ 2022-03-27 22:12 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-03-27 22:12 UTC (permalink / raw)
To: jianchunfu; +Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio
On Thu, Mar 24, 2022 at 3:15 PM jianchunfu
<jianchunfu@cmss.chinamobile.com> wrote:
>
> Add judgment to fix the potential stack overflow risk.
> trigger_name = malloc(IIO_MAX_NAME_LENGTH);
> + if (!trigger_name) {
> + ret = -ENOMEM;
> + goto error;
> + }
Isn't malloc() sets errno? Why not use it instead?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-27 22:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-24 11:01 [PATCH] tools:iio: Fix the potential stack overflow risk jianchunfu
2022-03-27 14:45 ` Jonathan Cameron
2022-03-27 22:12 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox