From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmOUq-0007NJ-0d for qemu-devel@nongnu.org; Tue, 20 Sep 2016 13:06:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmOUl-0007Q1-OM for qemu-devel@nongnu.org; Tue, 20 Sep 2016 13:06:14 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43470 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmOUl-0007Pc-Hx for qemu-devel@nongnu.org; Tue, 20 Sep 2016 13:06:11 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8KH3KHo109418 for ; Tue, 20 Sep 2016 13:06:11 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0b-001b2d01.pphosted.com with ESMTP id 25jnxcc474-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 20 Sep 2016 13:06:11 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Sep 2016 11:06:09 -0600 From: Michael Roth Date: Tue, 20 Sep 2016 12:05:33 -0500 In-Reply-To: <1474391141-16623-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1474391141-16623-1-git-send-email-mdroth@linux.vnet.ibm.com> Message-Id: <1474391141-16623-18-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 17/25] qemu-char: avoid segfault if user lacks of permisson of a given logfile List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Lin Ma , Paolo Bonzini From: Lin Ma Function qemu_chr_alloc returns NULL if it failed to open logfile by any reason, says no write permission. For backends tty, stdio and msmouse, They need to check this return value to avoid segfault in this case. Signed-off-by: Lin Ma Cc: qemu-stable Message-Id: <20160914062250.22226-1-lma@suse.com> Signed-off-by: Paolo Bonzini (cherry picked from commit 71200fb9664c2967a1cdd22b68b0da3a8b2b3eb7) Signed-off-by: Michael Roth --- qemu-char.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qemu-char.c b/qemu-char.c index b597ee1..05d602b 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1217,6 +1217,9 @@ static CharDriverState *qemu_chr_open_stdio(const char *id, sigaction(SIGCONT, &act, NULL); chr = qemu_chr_open_fd(0, 1, common, errp); + if (!chr) { + return NULL; + } chr->chr_close = qemu_chr_close_stdio; chr->chr_set_echo = qemu_chr_set_echo_stdio; if (opts->has_signal) { @@ -1673,6 +1676,9 @@ static CharDriverState *qemu_chr_open_tty_fd(int fd, tty_serial_init(fd, 115200, 'N', 8, 1); chr = qemu_chr_open_fd(fd, fd, backend, errp); + if (!chr) { + return NULL; + } chr->chr_ioctl = tty_serial_ioctl; chr->chr_close = qemu_chr_close_tty; return chr; -- 1.9.1