zpcictl: Check for regular directory

In case a regular directory was specified, rather than a device node,
the check if the device exists will pass. The following code paths then
assume a slot id was specified. This in turn may lead to a buffer
overflow when the device data is copied to to the zpci_device struct.

Check if the specified path is a regular directory and prevent a
possible later buffer overflow and copying wrong data respectively.

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2019-04-01 09:53:06 +02:00
parent be7b854969
commit c7a255fcd9

View File

@@ -253,8 +253,12 @@ static int device_exists(char *dev)
char *path;
int rc = 0;
/* In case a device node is specified, this will be sufficiant */
if (util_path_exists(dev) && !util_path_is_dir(dev))
return 1;
path = util_path_sysfs("bus/pci/devices/%s", dev);
if (util_path_exists(path) || util_path_exists(dev))
if (util_path_exists(path))
rc = 1;
free(path);