qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Longpeng(Mike)" <longpeng2@huawei.com>
To: <mst@redhat.com>, <alex.williamson@redhat.com>
Cc: longpeng2@huawei.com, arei.gonglei@huawei.com,
	huangzhichao@huawei.com, qemu-devel@nongnu.org,
	weifuqiang@huawei.com
Subject: [PATCH RESEND 3/3] util/pty: fix a null pointer reference in qemu_openpty_raw
Date: Mon, 24 Feb 2020 14:42:19 +0800	[thread overview]
Message-ID: <20200224064219.1434-4-longpeng2@huawei.com> (raw)
In-Reply-To: <20200224064219.1434-1-longpeng2@huawei.com>

From: Longpeng <longpeng2@huawei.com>

q_ptsname may failed ane return null, so use the returned pointer
as the param of strcpy will cause null pointer deference. Use the
return string of openpty instead of call ptsname.

Signed-off-by: Longpeng <longpeng2@huawei.com>
---
 util/qemu-openpty.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/util/qemu-openpty.c b/util/qemu-openpty.c
index 2e8b43b..2bea4ba 100644
--- a/util/qemu-openpty.c
+++ b/util/qemu-openpty.c
@@ -112,13 +112,7 @@ int qemu_openpty_raw(int *aslave, char *pty_name)
 {
     int amaster;
     struct termios tty;
-#if defined(__OpenBSD__) || defined(__DragonFly__)
-    char pty_buf[PATH_MAX];
-#define q_ptsname(x) pty_buf
-#else
-    char *pty_buf = NULL;
-#define q_ptsname(x) ptsname(x)
-#endif
+    char pty_buf[PATH_MAX] = { 0 };
 
     if (openpty(&amaster, aslave, pty_buf, NULL, NULL) < 0) {
         return -1;
@@ -130,7 +124,7 @@ int qemu_openpty_raw(int *aslave, char *pty_name)
     tcsetattr(*aslave, TCSAFLUSH, &tty);
 
     if (pty_name) {
-        strcpy(pty_name, q_ptsname(amaster));
+        strcpy(pty_name, pty_buf);
     }
 
     return amaster;
-- 
1.8.3.1



      parent reply	other threads:[~2020-02-24  6:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24  6:42 [PATCH RESEND 0/3] fix some warnings by static code scan tool Longpeng(Mike)
2020-02-24  6:42 ` [PATCH RESEND 1/3] vfio/pci: fix a null pointer reference in vfio_rom_read Longpeng(Mike)
2020-02-24 16:04   ` Alex Williamson
2020-02-24 23:48     ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2020-03-10 16:11       ` Alex Williamson
2020-03-10 23:14         ` Laszlo Ersek
2020-03-11  1:36           ` Alex Williamson
2020-03-11  7:08             ` Markus Armbruster
2020-03-11 10:28               ` Laszlo Ersek
2020-03-11 10:26             ` Laszlo Ersek
2020-03-11 11:54               ` Markus Armbruster
2020-03-11 13:00                 ` Laszlo Ersek
2020-03-11  7:04     ` Markus Armbruster
     [not found]       ` <20200311093939.494bfe27@w520.home>
2020-03-12  5:50         ` Markus Armbruster
2020-03-12 14:07           ` Alex Williamson
2020-02-24  6:42 ` [PATCH RESEND 2/3] vhost: fix a null pointer reference of vhost_log Longpeng(Mike)
2020-03-10  2:11   ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2020-03-10  5:57   ` Michael S. Tsirkin
2020-03-10  8:04     ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2020-03-10  8:23       ` Michael S. Tsirkin
2020-03-10 12:02         ` Longpeng (Mike)
2020-03-10 12:18           ` Michael S. Tsirkin
2020-02-24  6:42 ` Longpeng(Mike) [this message]

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=20200224064219.1434-4-longpeng2@huawei.com \
    --to=longpeng2@huawei.com \
    --cc=alex.williamson@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=huangzhichao@huawei.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=weifuqiang@huawei.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).