diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index bd1932dcb..4dc142c5b 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -13,6 +13,9 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) { FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY, 0); + if (fd < 0) + return "open(\"/dev/pci\", O_RDONLY, 0) failed"; + struct pci_conf confs[128]; struct pci_match_conf match = { .pc_class = PCIC_DISPLAY, @@ -78,7 +81,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) ffGPUQueryAmdGpuName(pc->pc_device, pc->pc_revid, gpu); if (gpu->name.length == 0) - ffGPUFillVendorAndName(pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu); + ffGPUFillVendorAndName(pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu); } if (gpu->type == FF_GPU_TYPE_UNKNOWN) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index ea108f460..f2073a69b 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -426,7 +426,9 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf } else { - pPciPath = memrchr(deviceDir->chars, '/', deviceDir->length) + 1; + pPciPath = memrchr(deviceDir->chars, '/', deviceDir->length); + assert(pPciPath); + pPciPath++; } uint32_t pciDomain, pciBus, pciDevice, pciFunc; diff --git a/src/detection/gpu/gpu_sunos.c b/src/detection/gpu/gpu_sunos.c index 5ea80eb09..b4d775c4a 100644 --- a/src/detection/gpu/gpu_sunos.c +++ b/src/detection/gpu/gpu_sunos.c @@ -35,8 +35,14 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* { // find the start of device entry const char* pstart = memrchr(buffer.chars, '\n', (size_t) (pclass - buffer.chars)); + if (pstart == NULL) + return "PCI info not found, invalid scanpci result"; while (pstart[1] != 'p') + { pstart = memrchr(buffer.chars, '\n', (size_t) (pstart - buffer.chars - 1)); + if (pstart == NULL) + return "PCI info not found, invalid scanpci result"; + } ++pstart; uint32_t vendorId, deviceId;