cryptodev: fix driver name comparison
authorAnoob Joseph <anoobj@marvell.com>
Mon, 11 Mar 2019 05:55:44 +0000 (05:55 +0000)
committerAkhil Goyal <akhil.goyal@nxp.com>
Fri, 22 Mar 2019 13:27:46 +0000 (14:27 +0100)
The string compare to the length of driver name might give false
positives when there are drivers with similar names (one being the
subset of another).

Following is such a naming which could result in false positive.
1. crypto_driver
2. crypto_driver1

When strncmp with len = strlen("crypto_driver") is done, it could give
a false positive when compared against "crypto_driver1". For such cases,
'strlen + 1' is done, so that the NULL termination also would be
considered for the comparison.

Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto devices")
Cc: stable@dpdk.org
Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
Signed-off-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
lib/librte_cryptodev/rte_cryptodev.c

index 7009735..871d7dd 100644 (file)
@@ -586,7 +586,7 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
 
                        cmp = strncmp(devs[i].device->driver->name,
                                        driver_name,
-                                       strlen(driver_name));
+                                       strlen(driver_name) + 1);
 
                        if (cmp == 0)
                                devices[count++] = devs[i].data->dev_id;
@@ -1691,7 +1691,7 @@ rte_cryptodev_driver_id_get(const char *name)
 
        TAILQ_FOREACH(driver, &cryptodev_driver_list, next) {
                driver_name = driver->driver->name;
-               if (strncmp(driver_name, name, strlen(driver_name)) == 0)
+               if (strncmp(driver_name, name, strlen(driver_name) + 1) == 0)
                        return driver->id;
        }
        return -1;