public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen.5i5j@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: dodji@redhat.com, kcc@google.com, dvyukov@google.com,
	 gcc-patches List <gcc-patches@gcc.gnu.org>,
	Jeff Law <law@redhat.com>
Subject: Re: [PATCH] libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc: Avoid writing '\0' out of string's border
Date: Mon, 01 Sep 2014 08:52:00 -0000	[thread overview]
Message-ID: <54043506.8090603@gmail.com> (raw)
In-Reply-To: <20140901084151.GH17454@tucnak.redhat.com>



On 9/1/14 16:41, Jakub Jelinek wrote:
> On Thu, Aug 28, 2014 at 06:43:02AM +0800, Chen Gang wrote:
>> 'max_len' is the maximized length of 'name', so for writing '\0' to
>> "name[max_len]", it is out of string's border, need use "max_len - 1"
>> instead of.
> 
> Depends on how the function's API is defined.
> And, at least in GCC sources that function seems to be completely unused,
> nothing calls it, so it is hard to guess what the API should be.
> 

For me, if we are sure it is useless in future, we need remove it, now.

If we are sure it is useful in the future, we need improve it in time
(before it is used), it is not a good idea to let both caller and callee
notice about '\0':

 - If caller has duty to notice about '\0', callee need not notice about
   it: remove "name[max_len] = 0;"

 - If callee has duty to notice about '\0', caller need not notice about
   it: use "max_len - 1" instead of "max_len".

 - For both cases, the related comments of declaration are redundancy,
   need be removed (or improved).

And for safety (also easy understanding) reason, I prefer to remove it
firstly.


Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed

      reply	other threads:[~2014-09-01  8:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27 22:43 Chen Gang
2014-08-27 22:51 ` Konstantin Serebryany
2014-08-27 22:58   ` Chen Gang
2014-08-30  3:53     ` Chen Gang
2014-09-01  8:42 ` Jakub Jelinek
2014-09-01  8:52   ` Chen Gang [this message]

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=54043506.8090603@gmail.com \
    --to=gang.chen.5i5j@gmail.com \
    --cc=dodji@redhat.com \
    --cc=dvyukov@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=kcc@google.com \
    --cc=law@redhat.com \
    /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 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 read-only IMAP folder(s) and NNTP newsgroup(s).