From c7a255fcd9433bba6dd516f6b28a139bbc5351d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Mon, 1 Apr 2019 09:53:06 +0200 Subject: [PATCH] zpcictl: Check for regular directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- zpcictl/zpcictl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zpcictl/zpcictl.c b/zpcictl/zpcictl.c index dfbbb78f..861bb3dd 100644 --- a/zpcictl/zpcictl.c +++ b/zpcictl/zpcictl.c @@ -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);