This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] gdbserver/hostio.c, handle_close: check for null


On Friday 04 March 2011 20:16:11, Michael Snyder wrote:
> This one's a little iffey...
> 
> The conditional in the while loop implies that the pointer may wind up 
> as null.  Therefore it would make sense to check it for null before 
> dereferencing it.
> 
> Alternatively, if it can't wind up as null, we should take the test out 
> of the while loop.

It can't wind up as null here.  The require_valid_fd() call up
in the function makes sure 'fd' exists in the list.
Either a gdb_assert or removing the check is fine.  But 
in either case, it'd be nice if it came with a comment
mentioning why it can't be NULL.

> 
> Michael
> 
> null1.txt
>   2011-03-04  Michael Snyder  <msnyder@vmware.com>
> 
>         * gdbserver/hostio.c (handle_close): Check for null before deref.
> 
> Index: gdbserver/hostio.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbserver/hostio.c,v
> retrieving revision 1.14
> diff -u -p -u -p -r1.14 hostio.c
> --- gdbserver/hostio.c  28 Feb 2011 15:55:08 -0000      1.14
> +++ gdbserver/hostio.c  4 Mar 2011 20:12:48 -0000
> @@ -422,7 +422,8 @@ handle_close (char *own_buf)
>      open_fd_p = &(*open_fd_p)->next;
>  
>    old_fd = *open_fd_p;
> -  *open_fd_p = (*open_fd_p)->next;
> +  if (*open_fd_p != NULL)
> +    *open_fd_p = (*open_fd_p)->next;
>    free (old_fd);
>  
>    hostio_reply (own_buf, ret);

-- 
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]