From 4b7f09a2862fdf8a7811083d88057048f237ef7a Mon Sep 17 00:00:00 2001 From: Anatoly Borodin Date: Thu, 21 Sep 2017 14:50:52 +0000 Subject: [PATCH] Use the right type for `len`, avoid segmentation fault `getline()` requires its second parameter to be `size_t *`. On the amd64 platform the size of `unsigned int` is 4 and the size of `size_t` is 8 bytes. Using a wrong pointer type can lead to a stack variables corruption (overwriting with zeros) and a segmentation fault later. See also similar `len` declarations in `_discover_get_pci_raw_sys()` in the docs and `_discover_get_ata_raw()` / `discover_get_pci_raw_proc()` / `discover_get_usb_raw()` in the source code. --- sysdeps/linux/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git sysdeps/linux/pci.c sysdeps/linux/pci.c index 1101f523de1b..42a20d323728 100644 --- sysdeps/linux/pci.c +++ sysdeps/linux/pci.c @@ -160,7 +160,7 @@ _discover_get_pci_raw_sys(void) FILE *f; DIR *pciDir; struct dirent *pci_device_entry; - unsigned int len; + size_t len = 0; char *device_dir, *line, *class, *vendor, *model, *p; char **device_dir_list = NULL; size_t device_dir_list_len, device_dir_index, device_dir_index2; -- 2.14.1