From: Anoob Joseph Date: Mon, 11 Mar 2019 05:55:44 +0000 (+0000) Subject: cryptodev: fix driver name comparison X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=2382aa8c8f5820a5783b32a82e364a63d486183f;p=dpdk.git cryptodev: fix driver name comparison 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 Signed-off-by: Anoob Joseph Acked-by: Fiona Trahe Acked-by: Akhil Goyal --- diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 7009735306..871d7dda8b 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -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;