From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id F30352BA1 for ; Thu, 7 Apr 2016 15:23:11 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 07 Apr 2016 06:23:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,449,1455004800"; d="scan'208";a="80874729" Received: from sie-lab-214-036.ir.intel.com (HELO sie-lab-214-36.ir.intel.com) ([10.237.214.36]) by fmsmga004.fm.intel.com with ESMTP; 07 Apr 2016 06:23:02 -0700 From: Pablo de Lara To: dev@dpdk.org Cc: declan.doherty@intel.com, Pablo de Lara Date: Thu, 7 Apr 2016 14:23:09 +0100 Message-Id: <1460035389-49395-1-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.5.5 Subject: [dpdk-dev] [PATCH] l2fwd-crypto: fix coverity defect X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2016 13:23:12 -0000 When parsing crypto device type, the string was being copied with strcpy(), which could overflow the destination buffer (which is 32 byte long), so snprintf() should be used instead. This fixes coverity issue 124575: /examples/l2fwd-crypto/main.c: 1005 in l2fwd_crypto_parse_args_long_options() *** CID 124575: (STRING_OVERFLOW) 999 1000 /* Authentication options */ 1001 else if (strcmp(lgopts[option_index].name, "auth_algo") == 0) { 1002 retval = parse_auth_algo(&options->auth_xform.auth.algo, 1003 optarg); 1004 if (retval == 0) >>> CID 124575: (STRING_OVERFLOW) >>> You might overrun the 32 byte fixed-size string "options->string_auth_algo" by copying "optarg" without checking the length. 1005 strcpy(options->string_auth_algo, optarg); 1006 return retval; 1007 } Fixes: commit 49f79e86480d ("examples/l2fwd-crypto: add missing string initialization") Signed-off-by: Pablo de Lara --- examples/l2fwd-crypto/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index 182dc56..d4e2d8d 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -1012,7 +1012,8 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, if (strcmp(lgopts[option_index].name, "cdev_type") == 0) { retval = parse_cryptodev_type(&options->type, optarg); if (retval == 0) - strcpy(options->string_type, optarg); + snprintf(options->string_type, MAX_STR_LEN, + "%s", optarg); return retval; } -- 2.5.5