2005-05-31 16:02:43

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: potential-null-pointer-dereference-in-amiga-serial-driver.patch added to -mm tree

On Tuesday 31 May 2005 13:08, [email protected] wrote:
> A pointer is dereferenced before it is null-checked.

> --- 25/drivers/char/amiserial.c~potential-null-pointer-dereference-in-amiga-serial-driver
> +++ 25-akpm/drivers/char/amiserial.c

> static void rs_put_char(struct tty_struct *tty, unsigned char ch)
> {
> - struct async_struct *info = (struct async_struct *)tty->driver_data;
> + struct async_struct *info;
> unsigned long flags;
>
> + if (!tty)
> + return;

Can ->put_char be ever called with tty being NULL? From my reading of
drivers/char/n_tty.c it can't.

Every single time ->put_char is used a-la

tty->driver->put_char(tty, '\r');

So, tty will be dereferenced before function call. Same for static inline
put_char() there.

> +
> + info = tty->driver_data;

> static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count)
> {

> - struct async_struct *info = (struct async_struct *)tty->driver_data;
> + struct async_struct *info;
> unsigned long flags;
>
> + if (!tty)
> + return 0;

Same question.

> +
> + info = tty->driver_data;


2005-05-31 17:14:43

by Marcelo Tosatti

[permalink] [raw]
Subject: Re: potential-null-pointer-dereference-in-amiga-serial-driver.patch added to -mm tree


Hi Alexey,

On Tue, May 31, 2005 at 07:49:15PM +0400, Alexey Dobriyan wrote:
> On Tuesday 31 May 2005 13:08, [email protected] wrote:
> > A pointer is dereferenced before it is null-checked.
>
> > --- 25/drivers/char/amiserial.c~potential-null-pointer-dereference-in-amiga-serial-driver
> > +++ 25-akpm/drivers/char/amiserial.c
>
> > static void rs_put_char(struct tty_struct *tty, unsigned char ch)
> > {
> > - struct async_struct *info = (struct async_struct *)tty->driver_data;
> > + struct async_struct *info;
> > unsigned long flags;
> >
> > + if (!tty)
> > + return;
>
> Can ->put_char be ever called with tty being NULL? From my reading of
> drivers/char/n_tty.c it can't.

Nope it can't, but the change makes the code more readable IMO, while handling
a NULL "tty" argument properly (which the old version pretends to, but doesnt).

> Every single time ->put_char is used a-la
>
> tty->driver->put_char(tty, '\r');
>
> So, tty will be dereferenced before function call. Same for static inline
> put_char() there.