Re: [PATCH] tools:iio: Fix the potential stack overflow risk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 24 Mar 2022 19:01:57 +0800
jianchunfu <jianchunfu@xxxxxxxxxxxxxxxxxxxx> wrote:

> Add judgment to fix the potential stack overflow risk.
> 
> Signed-off-by: jianchunfu <jianchunfu@xxxxxxxxxxxxxxxxxxxx>
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) {




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux