drivers/crypto: use snprintf return value correctly
authorTomasz Duszynski <tdu@semihalf.com>
Wed, 11 Oct 2017 11:05:07 +0000 (13:05 +0200)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 12 Oct 2017 14:22:39 +0000 (15:22 +0100)
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 <tdu@semihalf.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
drivers/crypto/aesni_gcm/aesni_gcm_pmd_ops.c
drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
drivers/crypto/armv8/rte_armv8_pmd_ops.c
drivers/crypto/kasumi/rte_kasumi_pmd_ops.c
drivers/crypto/null/null_crypto_pmd_ops.c
drivers/crypto/openssl/rte_openssl_pmd_ops.c
drivers/crypto/snow3g/rte_snow3g_pmd_ops.c
drivers/crypto/zuc/rte_zuc_pmd_ops.c

index 48400ac..0f315f0 100644 (file)
@@ -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;
index 2e52ac2..3b3ef0c 100644 (file)
@@ -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);
index 00297be..63776b2 100644 (file)
@@ -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;
index 8033114..4da12f3 100644 (file)
@@ -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;
index 7615320..c427050 100644 (file)
@@ -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;
index e1c225d..c572239 100644 (file)
@@ -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;
index ae9569c..157a2de 100644 (file)
@@ -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;
index 52c6aed..243c099 100644 (file)
@@ -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;