From 6ab25e634f51b98b18bd3095cd09858c4a9489fe Mon Sep 17 00:00:00 2001 From: Tomasz Duszynski Date: Wed, 11 Oct 2017 13:05:07 +0200 Subject: [PATCH] drivers/crypto: use snprintf return value correctly snprintf return value is the length of was encoded into destination array excluding '\0'. Thus return value equal to the length of the destination array or more means truncation. This commit fixes improper use of the return value. Fixes: eec136f3c54f ("aesni_gcm: add driver for AES-GCM crypto operations") Fixes: 924e84f87306 ("aesni_mb: add driver for multi buffer based crypto") Fixes: 0f548b50a160 ("crypto/aesni_mb: process crypto op on dequeue") Fixes: 169ca3db550c ("crypto/armv8: add PMD optimized for ARMv8 processors") Fixes: 2773c86d061a ("crypto/kasumi: add driver for KASUMI library") Fixes: 94b0ad8e0aa5 ("null_crypto: add driver for null crypto operations") Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library") Fixes: 3aafc423cf4d ("snow3g: add driver for SNOW 3G library") Fixes: cf7685d68f00 ("crypto/zuc: add driver for ZUC library") Cc: stable@dpdk.org Signed-off-by: Tomasz Duszynski Acked-by: Bruce Richardson --- drivers/crypto/aesni_gcm/aesni_gcm_pmd_ops.c | 2 +- drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c | 4 ++-- drivers/crypto/armv8/rte_armv8_pmd_ops.c | 2 +- drivers/crypto/kasumi/rte_kasumi_pmd_ops.c | 2 +- drivers/crypto/null/null_crypto_pmd_ops.c | 2 +- drivers/crypto/openssl/rte_openssl_pmd_ops.c | 2 +- drivers/crypto/snow3g/rte_snow3g_pmd_ops.c | 2 +- drivers/crypto/zuc/rte_zuc_pmd_ops.c | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/aesni_gcm/aesni_gcm_pmd_ops.c b/drivers/crypto/aesni_gcm/aesni_gcm_pmd_ops.c index 48400ac2a8..0f315f008c 100644 --- a/drivers/crypto/aesni_gcm/aesni_gcm_pmd_ops.c +++ b/drivers/crypto/aesni_gcm/aesni_gcm_pmd_ops.c @@ -195,7 +195,7 @@ aesni_gcm_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "aesni_gcm_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c index 2e52ac2c52..3b3ef0c08d 100644 --- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c +++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c @@ -397,7 +397,7 @@ aesni_mb_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "aesni_mb_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; @@ -415,7 +415,7 @@ aesni_mb_pmd_qp_create_processed_ops_ring(struct aesni_mb_qp *qp, "%s_%s", qp->name, str); - if (n > sizeof(ring_name)) + if (n >= sizeof(ring_name)) return NULL; r = rte_ring_lookup(ring_name); diff --git a/drivers/crypto/armv8/rte_armv8_pmd_ops.c b/drivers/crypto/armv8/rte_armv8_pmd_ops.c index 00297bebb1..63776b2628 100644 --- a/drivers/crypto/armv8/rte_armv8_pmd_ops.c +++ b/drivers/crypto/armv8/rte_armv8_pmd_ops.c @@ -209,7 +209,7 @@ armv8_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev, n = snprintf(qp->name, sizeof(qp->name), "armv8_crypto_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; diff --git a/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c b/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c index 8033114b77..4da12f3776 100644 --- a/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c +++ b/drivers/crypto/kasumi/rte_kasumi_pmd_ops.c @@ -183,7 +183,7 @@ kasumi_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "kasumi_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; diff --git a/drivers/crypto/null/null_crypto_pmd_ops.c b/drivers/crypto/null/null_crypto_pmd_ops.c index 7615320341..c427050a67 100644 --- a/drivers/crypto/null/null_crypto_pmd_ops.c +++ b/drivers/crypto/null/null_crypto_pmd_ops.c @@ -175,7 +175,7 @@ null_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "null_crypto_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c index e1c225d08e..c572239918 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c +++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c @@ -599,7 +599,7 @@ openssl_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "openssl_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd_ops.c b/drivers/crypto/snow3g/rte_snow3g_pmd_ops.c index ae9569c87b..157a2de363 100644 --- a/drivers/crypto/snow3g/rte_snow3g_pmd_ops.c +++ b/drivers/crypto/snow3g/rte_snow3g_pmd_ops.c @@ -184,7 +184,7 @@ snow3g_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "snow3g_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; diff --git a/drivers/crypto/zuc/rte_zuc_pmd_ops.c b/drivers/crypto/zuc/rte_zuc_pmd_ops.c index 52c6aed849..243c0991d3 100644 --- a/drivers/crypto/zuc/rte_zuc_pmd_ops.c +++ b/drivers/crypto/zuc/rte_zuc_pmd_ops.c @@ -184,7 +184,7 @@ zuc_pmd_qp_set_unique_name(struct rte_cryptodev *dev, "zuc_pmd_%u_qp_%u", dev->data->dev_id, qp->id); - if (n > sizeof(qp->name)) + if (n >= sizeof(qp->name)) return -1; return 0; -- 2.20.1