All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <anton@enomsg.org>
To: Chen Gang <gang.chen@asianux.com>
Cc: jason.wessel@windriver.com, sasha.levin@oracle.com,
	vincent.stehle@laposte.net, john.blackwood@ccur.com,
	kgdb-bugreport@lists.sourceforge.net,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kernel: debug: kdb: strncpy issue, using strlcpy instead of strncpy.
Date: Tue, 23 Apr 2013 16:50:11 -0400	[thread overview]
Message-ID: <20130423205011.GA5915@teo> (raw)
In-Reply-To: <516E6EB1.70100@asianux.com>

On Wed, Apr 17, 2013 at 05:43:13PM +0800, Chen Gang wrote:
> Hello maintainers:
> 
>   please help check this patch, when you have time, thanks.
> 

The patch looks good. I would add to the description: "..., otherwise the
destination string might end up not being terminted with the NUL, causing
all sorts of misbehaviour."

	Acked-by: Anton Vorontsov <anton@enomsg.org>

Thanks!

> On 2013年04月07日 19:03, Chen Gang wrote:
> > 
> >   cmd_cur and cmd_hist[] are all NUL terminated string.
> >   need using strlcpy instead of strncpy.
> > 
> > Signed-off-by: Chen Gang <gang.chen@asianux.com>
> > ---
> >  kernel/debug/kdb/kdb_main.c |    8 ++++----
> >  1 files changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> > index 00eb8f7..a2b04d7 100644
> > --- a/kernel/debug/kdb/kdb_main.c
> > +++ b/kernel/debug/kdb/kdb_main.c
> > @@ -1063,12 +1063,12 @@ static int handle_ctrl_cmd(char *cmd)
> >  	case CTRL_P:
> >  		if (cmdptr != cmd_tail)
> >  			cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT;
> > -		strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
> > +		strlcpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
> >  		return 1;
> >  	case CTRL_N:
> >  		if (cmdptr != cmd_head)
> >  			cmdptr = (cmdptr+1) % KDB_CMD_HISTORY_COUNT;
> > -		strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
> > +		strlcpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
> >  		return 1;
> >  	}
> >  	return 0;
> > @@ -1260,7 +1260,7 @@ do_full_getstr:
> >  		if (*cmdbuf != '\n') {
> >  			if (*cmdbuf < 32) {
> >  				if (cmdptr == cmd_head) {
> > -					strncpy(cmd_hist[cmd_head], cmd_cur,
> > +					strlcpy(cmd_hist[cmd_head], cmd_cur,
> >  						CMD_BUFLEN);
> >  					*(cmd_hist[cmd_head] +
> >  					  strlen(cmd_hist[cmd_head])-1) = '\0';
> > @@ -1270,7 +1270,7 @@ do_full_getstr:
> >  				cmdbuf = cmd_cur;
> >  				goto do_full_getstr;
> >  			} else {
> > -				strncpy(cmd_hist[cmd_head], cmd_cur,
> > +				strlcpy(cmd_hist[cmd_head], cmd_cur,
> >  					CMD_BUFLEN);
> >  			}
> >  
> > 
> 
> 
> -- 
> Chen Gang
> 
> Asianux Corporation

  reply	other threads:[~2013-04-23 21:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07 11:03 [PATCH] kernel: debug: kdb: strncpy issue, using strlcpy instead of strncpy Chen Gang
2013-04-17  9:43 ` Chen Gang
2013-04-23 20:50   ` Anton Vorontsov [this message]
2013-04-24  1:12     ` Chen Gang
  -- strict thread matches above, loose matches on Subject: below --
2013-04-07 11:20 Chen Gang
2013-04-17  9:43 ` Chen Gang
2013-05-16 11:38 Chen Gang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130423205011.GA5915@teo \
    --to=anton@enomsg.org \
    --cc=gang.chen@asianux.com \
    --cc=jason.wessel@windriver.com \
    --cc=john.blackwood@ccur.com \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sasha.levin@oracle.com \
    --cc=vincent.stehle@laposte.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.