Patchwork [iproute2,4/7] ip/xfrm: Do not print a zero-length algorithm key

login
register
mail settings
Submitter David Ward
Date March 25, 2013, 2:23 p.m.
Message ID <1364221399-1024-4-git-send-email-david.ward@ll.mit.edu>
Download mbox | patch
Permalink /patch/230727/
State Accepted
Delegated to: stephen hemminger
Headers show

Comments

David Ward - March 25, 2013, 2:23 p.m.
Signed-off-by: David Ward <david.ward@ll.mit.edu>
---
 ip/ipxfrm.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

Patch

diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 2576938..3113573 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -536,12 +536,14 @@  static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
 		goto fin;
 	}
 
-	fprintf(fp, "0x");
-	for (i = 0; i < keylen; i ++)
-		fprintf(fp, "%.2x", (unsigned char)algo->alg_key[i]);
+	if (keylen > 0) {
+		fprintf(fp, "0x");
+		for (i = 0; i < keylen; i ++)
+			fprintf(fp, "%.2x", (unsigned char)algo->alg_key[i]);
 
-	if (show_stats > 0)
-		fprintf(fp, " (%d bits)", algo->alg_key_len);
+		if (show_stats > 0)
+			fprintf(fp, " (%d bits)", algo->alg_key_len);
+	}
 
  fin:
 	if (newline)