All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux.com>
To: Jiri Slaby <jslaby@suse.cz>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	tklauser@distanz.ch, wfp5p@virginia.edu,
	linuxppc-dev@lists.ozlabs.org, alan@linux.intel.com
Subject: Re: [PATCH] drivers/tty/hvc: using strlcpy instead of strncpy
Date: Thu, 28 Feb 2013 19:13:09 +0800	[thread overview]
Message-ID: <512F3BC5.8020903@asianux.com> (raw)
In-Reply-To: <512F343E.7010201@suse.cz>

于 2013年02月28日 18:41, Jiri Slaby 写道:
> On 02/26/2013 04:43 AM, Chen Gang wrote:
>> > 
>> >   when strlen pi->location_code is larger than HVCS_CLC_LENGTH + 1,
>> >     original implementation can not let hvcsd->p_location_code NUL terminated.
>> >   so need fix it (also can simplify the code)
> It should never be larger because the +1 is exactly for NUL. But it is a
> cleanup, so why not...
>

  when strlen(&pi->location_code[0]) == HVCS_CLC_LENGTH + 2
    then clclength will be reset to HVCS_CLC_LENGTH.

    when call strncpy, the clclength + 1 == HVCS_CLS_LENGTH + 1
      but the '\0' of src buf is located at HVCS_CLS_LENGTH + 2.
      so no '\0' copied to dest buf.

    then the dest buf will not be ended by '\0'.

  is it correct ?

  :-)

gchen.
 
>> > Signed-off-by: Chen Gang <gang.chen@asianux.com>
>> > ---
>> >  drivers/tty/hvc/hvcs.c |    9 ++-------
>> >  1 files changed, 2 insertions(+), 7 deletions(-)
>> > 
>> > diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
>> > index 1956593..81e939e 100644
>> > --- a/drivers/tty/hvc/hvcs.c
>> > +++ b/drivers/tty/hvc/hvcs.c
>> > @@ -881,17 +881,12 @@ static struct vio_driver hvcs_vio_driver = {
>> >  /* Only called from hvcs_get_pi please */
>> >  static void hvcs_set_pi(struct hvcs_partner_info *pi, struct hvcs_struct *hvcsd)
>> >  {
>> > -	int clclength;
>> > -
>> >  	hvcsd->p_unit_address = pi->unit_address;
>> >  	hvcsd->p_partition_ID  = pi->partition_ID;
>> > -	clclength = strlen(&pi->location_code[0]);
>> > -	if (clclength > HVCS_CLC_LENGTH)
>> > -		clclength = HVCS_CLC_LENGTH;
>> >  
>> >  	/* copy the null-term char too */
>> > -	strncpy(&hvcsd->p_location_code[0],
>> > -			&pi->location_code[0], clclength + 1);
>> > +	strlcpy(&hvcsd->p_location_code[0],
>> > +			&pi->location_code[0], sizeof(hvcsd->p_location_code));
>> >  }
>> >  
>> >  /*
>> > 


-- 
Chen Gang

Asianux Corporation

  reply	other threads:[~2013-02-28 11:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26  3:43 [PATCH] drivers/tty/hvc: using strlcpy instead of strncpy Chen Gang
2013-02-28 10:41 ` Jiri Slaby
2013-02-28 11:13   ` Chen Gang [this message]
2013-02-28 11:15     ` Chen Gang
2013-02-28 13:47       ` Jiri Slaby
2013-03-05  1:58         ` Chen Gang
2013-03-05  9:36           ` Jiri Slaby
2013-03-07  4:10             ` Chen Gang
2013-03-07  4:34               ` Chen Gang
2013-03-07  6:05                 ` Benjamin Herrenschmidt
2013-03-07  7:10                   ` Chen Gang
2013-03-08  3:38                   ` [PATCH] drivers/tty/hvc: fixup original commit: 9276dfd27897a0b29d8b5814f39a1f82f56b6b6b Chen Gang
2013-03-08  3:46                     ` Benjamin Herrenschmidt
2013-03-08  4:23                       ` Chen Gang
2013-03-08  4:33                         ` Benjamin Herrenschmidt
2013-03-08  4:40                           ` Chen Gang
2013-03-08  5:08                             ` Benjamin Herrenschmidt
2013-03-08  6:12                               ` Chen Gang
2013-03-08 11:11                       ` David Laight
2013-03-10  1:18                         ` 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=512F3BC5.8020903@asianux.com \
    --to=gang.chen@asianux.com \
    --cc=alan@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=tklauser@distanz.ch \
    --cc=wfp5p@virginia.edu \
    /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.