diff --git a/plugins/sysinfo/unix/modern-backend.c b/plugins/sysinfo/unix/modern-backend.c index ae079dbd..304777b2 100644 --- a/plugins/sysinfo/unix/modern-backend.c +++ b/plugins/sysinfo/unix/modern-backend.c @@ -116,7 +116,7 @@ read_hex_file (const char *path, guint *value) errno = 0; parsed = g_ascii_strtoull (contents, &end, 16); - if (errno != 0 || end == contents) + if (errno != 0 || end == contents || *end != '\0' || parsed > G_MAXUINT || contents[0] == '-') { g_free (contents); return FALSE; @@ -535,19 +535,22 @@ scan_pci_devices (void) gpus = g_ptr_array_new_with_free_func (g_free); chipsets = g_ptr_array_new_with_free_func (g_free); + dir = g_dir_open ("/sys/bus/pci/devices", 0, NULL); #ifdef HAVE_LIBPCI - /* We only need name lookup: autodetection can exit the client if sysfs - * is hidden in a sandbox and libpci tries privileged access methods. - * Explicit sysfs initialization installs callbacks without probing. */ - if (pci_lookup_method ("linux-sysfs") >= 0) + /* Only initialize the explicit sysfs method when PCI is visible. Never + * use autodetection or ask libpci to probe/configure a device. */ + if (dir) { - pacc = pci_alloc (); - pacc->method = pci_lookup_method ("linux-sysfs"); - pci_init (pacc); + int method = pci_lookup_method ("linux-sysfs"); + if (method >= 0) + { + pacc = pci_alloc (); + pacc->method = method; + pci_init (pacc); + } } #endif - dir = g_dir_open ("/sys/bus/pci/devices", 0, NULL); if (dir) { while ((entry = g_dir_read_name (dir)) != NULL) @@ -614,8 +617,9 @@ scan_pci_devices (void) g_free (gpu_name); } } - else if (class_subclass == 0x0600) + else if (class_subclass == 0x0600 || class_subclass == 0x0601) { + /* Include host bridges and ISA/LPC bridges. */ ptr_array_add_unique (chipsets, name); } @@ -821,7 +825,8 @@ sysinfo_backend_get_uptime (void) } uptime = g_ascii_strtod (contents, &end); - if (end == contents || uptime <= 0.0) + /* Comparisons also reject NaN, infinity and out-of-range conversions. */ + if (end == contents || !(uptime >= 0.0 && uptime < (double) G_MAXINT64)) { g_free (contents); return NULL; diff --git a/plugins/sysinfo/unix/pci.c b/plugins/sysinfo/unix/pci.c index fac2f76e..229d3ed5 100644 --- a/plugins/sysinfo/unix/pci.c +++ b/plugins/sysinfo/unix/pci.c @@ -51,12 +51,18 @@ static struct device *scan_device(struct pci_dev *p) d = g_new0 (struct device, 1); d->dev = p; if (!pci_read_block(p, 0, d->config, how_much)) - exit(1); + { + g_free (d); + return NULL; + } if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS) { /* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */ if (!pci_read_block(p, 64, d->config+64, 64)) - exit(1); + { + g_free (d); + return NULL; + } how_much = 128; } d->config_cnt = how_much; @@ -116,6 +122,14 @@ int pci_find_by_class(u16 *class, char *vendor, char *device) } pci_cleanup(pacc); + pacc = NULL; + /* Free the cached configuration buffers after libpci is done with them. */ + while (first_dev) + { + d = first_dev; + first_dev = d->next; + g_free (d); + } return nomatch; } @@ -142,8 +156,7 @@ void pci_find_fullname(char *fullname, char *vendor, char *device) position = strstr(buffer, vendor); position += 6; g_strlcpy(vendorname, position, sizeof (vendorname)); - position = strstr(vendorname, "\n"); - *(position) = '\0'; + g_strchomp (vendorname); break; } } @@ -155,9 +168,9 @@ void pci_find_fullname(char *fullname, char *vendor, char *device) position += 6; g_strlcpy(devicename, position, sizeof (devicename)); position = strstr(devicename, " ("); - if (position == NULL) - position = strstr(devicename, "\n"); - *(position) = '\0'; + if (position) + *position = '\0'; + g_strchomp (devicename); cardfound = 1; break; }