Re: Re: [PATCH] dev/parport: fix the array out-of-bounds risk

From: Greg KH
Date: Fri Jul 05 2024 - 05:42:28 EST


On Fri, Jul 05, 2024 at 04:58:34PM +0800, tuhaowen wrote:
> On Fri, Jul 05, 2024 at 02:45:45PM +0800, Greg Kroah-Hartman wrote:
>
> > I'm not disputing that this change looks correct, I'm asking that you
> > redo it and properly check the array size when writing to it so as to
> > ensure that it really is correct in case our math is incorrect
> > somewhere.
>
> Thank you for your feedback. I have redone the change and
> ensured that the array size is properly checked when writing to it.
> Please find my updated patch below.
>
> Thanks,
>
> Haowen.Tu
>
>
> >From cfdf8445987147f3a7e4f1232a8c6e8a271e4a6d Mon Sep 17 00:00:00 2001
> From: tuhaowen <tuhaowen@xxxxxxxxxxxxx>
> Date: Mon, 27 May 2024 14:34:32 +0800
> Subject: [PATCH] dev/parport: fix the array out-of-bounds risk

Sorry, we can't take inline patches like this, please read the
documentation for how to submit a new version of a patch.

But, some comments below:

> for (dev = port->devices; dev ; dev = dev->next) {
> if(dev == port->cad) {
> - len += sprintf(buffer, "%s\n", dev->name);
> + len += snprintf(buffer, 64, "%s\n", dev->name);

Don't use magic numbers here and everywhere else, use sizeof() to
compute these properly everywhere.

thanks,

greg k-h