From 902f6e14fc68743ce24efb7d87dc3f8464a78bf3 Mon Sep 17 00:00:00 2001 From: Ross Lagerwall Date: Wed, 1 Nov 2017 14:25:24 +0000 Subject: io: Fix QIOChannelFile when creating and opening read-write The code wrongly passes the mode to open() only if O_WRONLY is set. Instead, the mode should be passed when O_CREAT is set (or O_TMPFILE on Linux). Fix this by always passing the mode since open() will correctly ignore the mode if it is not needed. Add a testcase which exercises this bug and also change the existing testcase to check that the mode of the created file is correct. Signed-off-by: Ross Lagerwall Signed-off-by: Daniel P. Berrange --- io/channel-file.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'io') diff --git a/io/channel-file.c b/io/channel-file.c index b383273201..16bf7ed270 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -50,11 +50,7 @@ qio_channel_file_new_path(const char *path, ioc = QIO_CHANNEL_FILE(object_new(TYPE_QIO_CHANNEL_FILE)); - if (flags & O_WRONLY) { - ioc->fd = open(path, flags, mode); - } else { - ioc->fd = open(path, flags); - } + ioc->fd = open(path, flags, mode); if (ioc->fd < 0) { object_unref(OBJECT(ioc)); error_setg_errno(errp, errno, -- cgit v1.2.1