[dpdk-dev,v2] examples/ipsec-secgw: fix copy into fixed size buffer issue

Message ID 1478528466-211016-1-git-send-email-roy.fan.zhang@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
tmonjalo/checkpatch success coding style OK

Commit Message

Fan Zhang Nov. 7, 2016, 2:21 p.m. UTC
  Fixes: 0d547ed0 ("examples/ipsec-secgw: support configuration
file")
Coverity issue: 137875

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
---
 examples/ipsec-secgw/sa.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
  

Comments

Ferruh Yigit Nov. 7, 2016, 3:59 p.m. UTC | #1
On 11/7/2016 2:21 PM, Fan Zhang wrote:
> Fixes: 0d547ed0 ("examples/ipsec-secgw: support configuration
> file")
> Coverity issue: 137875
> 
> Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Thomas Monjalon Nov. 7, 2016, 8:40 p.m. UTC | #2
2016-11-07 15:59, Ferruh Yigit:
> On 11/7/2016 2:21 PM, Fan Zhang wrote:
> > Fixes: 0d547ed0 ("examples/ipsec-secgw: support configuration
> > file")
> > Coverity issue: 137875
> > 
> > Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied
  

Patch

diff --git a/examples/ipsec-secgw/sa.c b/examples/ipsec-secgw/sa.c
index 9e2c8a9..8c4406c 100644
--- a/examples/ipsec-secgw/sa.c
+++ b/examples/ipsec-secgw/sa.c
@@ -170,15 +170,18 @@  static uint32_t
 parse_key_string(const char *key_str, uint8_t *key)
 {
 	const char *pt_start = key_str, *pt_end = key_str;
-	char sub_str[3];
 	uint32_t nb_bytes = 0;
 
 	while (pt_end != NULL) {
+		char sub_str[3] = {0};
+
 		pt_end = strchr(pt_start, ':');
 
-		if (pt_end == NULL)
-			strncpy(sub_str, pt_start, strlen(pt_start));
-		else {
+		if (pt_end == NULL) {
+			if (strlen(pt_start) > 2)
+				return 0;
+			strncpy(sub_str, pt_start, 2);
+		} else {
 			if (pt_end - pt_start > 2)
 				return 0;