From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6Yq-0004TM-Ct for qemu-devel@nongnu.org; Mon, 23 Jun 2014 11:53:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz6Yj-0001nw-Li for qemu-devel@nongnu.org; Mon, 23 Jun 2014 11:53:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6Yj-0001nk-Cu for qemu-devel@nongnu.org; Mon, 23 Jun 2014 11:53:29 -0400 Date: Mon, 23 Jun 2014 18:53:51 +0300 From: "Michael S. Tsirkin" Message-ID: <1403538745-18622-14-git-send-email-mst@redhat.com> References: <1403538745-18622-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1403538745-18622-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 13/23] qemu-char: fix qemu_chr_fe_get_msgfd() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Nikolay Nikolaev , Stefan Hajnoczi , Anthony Liguori From: Stefan Hajnoczi Commit c76bf6bb8fbbb233a7d3641e09229d23747d5ee3 ("Add chardev API qemu_chr_fe_get_msgfds") broke qemu_chr_fe_get_msgfd() because it changed the return value. Callers expect -1 if no fd is available. The commit changed the return value to 0 (which is a valid file descriptor number) so callers always detected a file descriptor even if none was available. This patch fixes qemu-iotests 045: $ cd tests/qemu-iotests && ./check 045 [...] +FAIL: test_add_fd_invalid_fd (__main__.TestFdSets) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "./045", line 123, in test_add_fd_invalid_fd + self.assert_qmp(result, 'error/class', 'GenericError') + File "/home/stefanha/qemu/tests/qemu-iotests/iotests.py", line 232, in assert_qmp + result = self.dictpath(d, path) + File "/home/stefanha/qemu/tests/qemu-iotests/iotests.py", line 211, in dictpath + self.fail('failed path traversal for "%s" in "%s"' % (path, str(d))) +AssertionError: failed path traversal for "error/class" in "{u'return': {u'fdset-id': 2, u'fd': 0}}" Cc: Nikolay Nikolaev Signed-off-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qemu-char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index e4eb985..d9100a2 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -204,7 +204,7 @@ void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len) int qemu_chr_fe_get_msgfd(CharDriverState *s) { int fd; - return (qemu_chr_fe_get_msgfds(s, &fd, 1) >= 0) ? fd : -1; + return (qemu_chr_fe_get_msgfds(s, &fd, 1) == 1) ? fd : -1; } int qemu_chr_fe_get_msgfds(CharDriverState *s, int *fds, int len) -- MST