Commit 6268520d authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Michael Tokarev
Browse files

pci-assign: do not test path with access() before opening



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: default avatarPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarMichael Tokarev <mjt@tls.msk.ru>
parent b30d8054
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -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;