Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <cagney@gnu.org>
To: Kevin Buettner <kevinb@redhat.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] remote.c: Avoid multiple serial_close calls on baud rate error
Date: Sun, 07 Dec 2003 01:57:00 -0000	[thread overview]
Message-ID: <3FD288FF.70009@gnu.org> (raw)
In-Reply-To: <1031205203631.ZM15513@localhost.localdomain>

> One of my colleagues recently noticed the following:
> 
>     (gdb) set remotebaud 0x100000
>     (gdb) target remote /dev/ttyS0
>     warning: Invalid baud rate 1048576.  Maximum value is 460800.
>     /dev/ttyS0: Invalid argument.
>     (gdb) set remotebaud 230400
>     (gdb) target remote /dev/ttyS0
>     Segmentation fault
> 
> The reason for this SEGV is that remote.c was closing ``remote_desc''
> twice.  On the second attempted close, it was accessing some data
> structures through some already freed (and probably even reallocated)
> memory.
> 
> The comment that I've added explains how the double close is avoided.
> 
> FWIW, I considered calling remote_close(), but decided against it
> since remote_desc can not be passed explicitly to this function. 
> Also, if the implementation of remote_close() were to change in some
> way, it may end up doing more (or less) than what's desired for
> handling the baud rate error.  Conversely, a hypothetical change in
> remote_close() may require that the error handling code be changed in
> a similar fashion, so the preferred path to fixing this problem isn't
> quite so clear cut.  Therefore, I'm willing to revise this patch to
> call remote_close() instead if that's deemed preferable.
> 
> With regard to the testcase above, it'd be nice if this could be added
> to the testsuite, but I can't think of a portable way of doing so.

Calling target_close() here wouldn't be right.  The target isn't yet 
open, the push call only occures further down.  This begs the question: 
why was open called twice?  I suspect unpush_target should only call 
target_close on open/pushed targets.

Anyway, this change is fine.  It makes the relevant code more robust.

Andrew



  parent reply	other threads:[~2003-12-07  1:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-05 20:36 Kevin Buettner
2003-12-05 21:04 ` Daniel Jacobowitz
2003-12-07  1:57 ` Andrew Cagney [this message]
2003-12-08 17:01   ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FD288FF.70009@gnu.org \
    --to=cagney@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=kevinb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox