[dpdk-dev] l2fwd-crypto: fix supported key size check

Message ID 1460455443-11130-1-git-send-email-pablo.de.lara.guarch@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

De Lara Guarch, Pablo April 12, 2016, 10:04 a.m. UTC
  When initializing crypto devices within the app,
the provided key sizes are checked against the supported
sizes from the crypto device capabilities.

When the supported sizes are not a range, but a single value,
the check may become an infinite loop (when size is not supported).

Fixes: a061e50a0d97 ("examples/l2fwd-crypto: fix ambiguous input key size")

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 examples/l2fwd-crypto/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Thomas Monjalon June 7, 2016, 8:23 p.m. UTC | #1
> When initializing crypto devices within the app,
> the provided key sizes are checked against the supported
> sizes from the crypto device capabilities.
> 
> When the supported sizes are not a range, but a single value,
> the check may become an infinite loop (when size is not supported).
> 
> Fixes: a061e50a0d97 ("examples/l2fwd-crypto: fix ambiguous input key size")
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Tested-by: Min Cao <min.cao@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index d4e2d8d..e273f2f 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -1486,6 +1486,15 @@  check_supported_size(uint16_t length, uint16_t min, uint16_t max,
 {
 	uint16_t supp_size;
 
+	/* Single value */
+	if (increment == 0) {
+		if (length == min)
+			return 0;
+		else
+			return -1;
+	}
+
+	/* Range of values */
 	for (supp_size = min; supp_size <= max; supp_size += increment) {
 		if (length == supp_size)
 			return 0;