All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: lustre: lustre: ptlrpc: nrs.c:  Cleaning up missing null-terminate after strncpy call
@ 2014-08-09 23:49 Rickard Strandqvist
  2014-08-11 10:58 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Rickard Strandqvist @ 2014-08-09 23:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Oleg Drokin
  Cc: Rickard Strandqvist, Liang Zhen, Andreas Dilger, Masanari Iida,
	Ann Koehler, devel, linux-kernel

Added a guaranteed null-terminate after call to strncpy.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/staging/lustre/lustre/ptlrpc/nrs.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
index 12151aa..a914447 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -1162,6 +1162,7 @@ int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
 		GOTO(fail, rc = -ENOMEM);
 
 	strncpy(desc->pd_name, conf->nc_name, NRS_POL_NAME_MAX);
+	desc->pd_name[NRS_POL_NAME_MAX - 1] = '\0';
 	desc->pd_ops		 = conf->nc_ops;
 	desc->pd_compat		 = conf->nc_compat;
 	desc->pd_compat_svc_name = conf->nc_compat_svc_name;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: lustre: lustre: ptlrpc: nrs.c: Cleaning up missing null-terminate after strncpy call
  2014-08-09 23:49 [PATCH] staging: lustre: lustre: ptlrpc: nrs.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
@ 2014-08-11 10:58 ` Dan Carpenter
  2014-08-11 20:36   ` Rickard Strandqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2014-08-11 10:58 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Greg Kroah-Hartman, Oleg Drokin, devel, Andreas Dilger,
	Liang Zhen, linux-kernel, Ann Koehler

On Sun, Aug 10, 2014 at 01:49:12AM +0200, Rickard Strandqvist wrote:
> Added a guaranteed null-terminate after call to strncpy.

No.  This is a problem in the static checker and not in the code.

Look at the start of the function.  This stuff should be obvious for the
static checker.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: lustre: lustre: ptlrpc: nrs.c: Cleaning up missing null-terminate after strncpy call
  2014-08-11 10:58 ` Dan Carpenter
@ 2014-08-11 20:36   ` Rickard Strandqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Rickard Strandqvist @ 2014-08-11 20:36 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Greg Kroah-Hartman, Oleg Drokin, devel, Andreas Dilger,
	Liang Zhen, linux-kernel, Ann Koehler

2014-08-11 12:58 GMT+02:00 Dan Carpenter <dan.carpenter@oracle.com>:
> On Sun, Aug 10, 2014 at 01:49:12AM +0200, Rickard Strandqvist wrote:
>> Added a guaranteed null-terminate after call to strncpy.
>
> No.  This is a problem in the static checker and not in the code.
>
> Look at the start of the function.  This stuff should be obvious for the
> static checker.
>
> regards,
> dan carpenter
>

Hi Dan

Okay, no, it was me who missed it, not cppcheck.

Ensuring that from string will fit was an unusual solution.
If I see code where an effort is made to ensure that no more than x
characters copied I react to it.
But it is zeroing of the string you were looking for then. Ok sorry :-(

Kind regards
Rickard Strandqvist

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-11 20:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-09 23:49 [PATCH] staging: lustre: lustre: ptlrpc: nrs.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
2014-08-11 10:58 ` Dan Carpenter
2014-08-11 20:36   ` Rickard Strandqvist

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.