* [dpdk-dev] [PATCH] l2fwd-crypto: fix coverity defect
@ 2016-04-07 13:23 Pablo de Lara
2016-04-07 16:00 ` Declan Doherty
0 siblings, 1 reply; 3+ messages in thread
From: Pablo de Lara @ 2016-04-07 13:23 UTC (permalink / raw)
To: dev; +Cc: declan.doherty, Pablo de Lara
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 <pablo.de.lara.guarch@intel.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] l2fwd-crypto: fix coverity defect
2016-04-07 13:23 [dpdk-dev] [PATCH] l2fwd-crypto: fix coverity defect Pablo de Lara
@ 2016-04-07 16:00 ` Declan Doherty
2016-04-07 17:51 ` Thomas Monjalon
0 siblings, 1 reply; 3+ messages in thread
From: Declan Doherty @ 2016-04-07 16:00 UTC (permalink / raw)
To: Pablo de Lara, dev
On 07/04/16 14:23, Pablo de Lara wrote:
> 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 <pablo.de.lara.guarch@intel.com>
> ---
...
>
Acked-by: Declan Doherty <declan.doherty@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] l2fwd-crypto: fix coverity defect
2016-04-07 16:00 ` Declan Doherty
@ 2016-04-07 17:51 ` Thomas Monjalon
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2016-04-07 17:51 UTC (permalink / raw)
To: Pablo de Lara; +Cc: dev, Declan Doherty
> > 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:
[...]
> > Fixes: commit 49f79e86480d ("examples/l2fwd-crypto: add missing string initialization")
> >
> > Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> >
> Acked-by: Declan Doherty <declan.doherty@intel.com>
Applied, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-07 17:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-07 13:23 [dpdk-dev] [PATCH] l2fwd-crypto: fix coverity defect Pablo de Lara
2016-04-07 16:00 ` Declan Doherty
2016-04-07 17:51 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).