qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Cc: Kevin Wolf <kwolf@redhat.com>,
	mitake.hitoshi@gmail.com, qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] qemu-io: initialize progname with error_set_progname()
Date: Mon, 11 Aug 2014 15:38:21 +0100	[thread overview]
Message-ID: <20140811143821.GD496@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1407739803-22699-1-git-send-email-mitake.hitoshi@lab.ntt.co.jp>

[-- Attachment #1: Type: text/plain, Size: 1259 bytes --]

On Mon, Aug 11, 2014 at 03:50:03PM +0900, Hitoshi Mitake wrote:
> Calling error_get_progname() in the context of qemu-io can cause
> segmentation fault because qemu-io doesn't initialize its progname
> with error_set_progname(). This patch adds the initialization.
> 
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
> ---
>  qemu-io.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/qemu-io.c b/qemu-io.c
> index b55a550..6f08a91 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -395,6 +395,7 @@ int main(int argc, char **argv)
>  #endif
>  
>      progname = basename(argv[0]);
> +    error_set_progname(progname);

From the basename(3) man page:

  These  functions  may return pointers to statically allocated memory which may be overwritten by subsequent calls.

Since error_set_progname() does not copy its argument, it is not safe to
pass the basename(3) return value.  Just pass in argv[0] like vl.c does.

Please also update the commit description to make it clear that
qemu-io currently does not use error_get_progname() so the crash doesn't
occur in practice (I guess you discovered it while modifying the code).

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  parent reply	other threads:[~2014-08-11 14:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-11  6:50 [Qemu-devel] [PATCH] qemu-io: initialize progname with error_set_progname() Hitoshi Mitake
2014-08-11 11:20 ` Markus Armbruster
2014-08-12  5:17   ` Hitoshi Mitake
2014-08-11 14:38 ` Stefan Hajnoczi [this message]
2014-08-12  5:21   ` Hitoshi Mitake

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=20140811143821.GD496@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=mitake.hitoshi@gmail.com \
    --cc=mitake.hitoshi@lab.ntt.co.jp \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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;
as well as URLs for NNTP newsgroup(s).