From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtFwK-00038f-Va for qemu-devel@nongnu.org; Mon, 02 Nov 2015 09:18:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtFwG-0006FI-G8 for qemu-devel@nongnu.org; Mon, 02 Nov 2015 09:18:28 -0500 From: Paolo Bonzini Date: Mon, 2 Nov 2015 15:17:37 +0100 Message-Id: <1446473857-11934-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org Using access() is a time-of-check/time-of-use race condition. It is okay to use them to provide better error messages, but that is pretty much it. In this case we can get the same error from fopen(), so just use strerror and errno there---which actually improves the error message most of the time. Signed-off-by: Paolo Bonzini --- hw/i386/pci-assign-load-rom.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hw/i386/pci-assign-load-rom.c b/hw/i386/pci-assign-load-rom.c index 34a3a7e..e40b586 100644 --- a/hw/i386/pci-assign-load-rom.c +++ b/hw/i386/pci-assign-load-rom.c @@ -45,14 +45,10 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, struct Object *owner, return NULL; } - if (access(rom_file, F_OK)) { - error_report("pci-assign: Insufficient privileges for %s", rom_file); - return NULL; - } - /* Write "1" to the ROM file to enable it */ fp = fopen(rom_file, "r+"); if (fp == NULL) { + error_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno)); return NULL; } val = 1; -- 2.5.0