From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: git <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] blame: prefer xsnprintf to strcpy for colors
Date: Fri, 13 Jul 2018 17:04:53 -0400 [thread overview]
Message-ID: <20180713210452.GA18909@sigill.intra.peff.net> (raw)
In-Reply-To: <CAGZ79kakrS_tk=x4Rb9qSu9e4RVSJ=J64eOdasKhOy=g8kV68w@mail.gmail.com>
On Fri, Jul 13, 2018 at 01:58:05PM -0700, Stefan Beller wrote:
> > I'm sad that this strcpy() wasn't caught in review. IMHO we should avoid
> > that function altogether, even when we _think_ it can't trigger an
> > overflow. That's easier to reason about (and makes auditing easier).
>
> Can we somehow automatically find "bad code" either in pathces
> or in new code (such as pu), e.g. as a coccicheck for these functions?
I'd be happy to declare strcpy() totally banned (and it more or less
is). I found this with a simple "git grep", though it seems like a
trivial application of coccinelle to find it. The question is what to
convert it into. xsnprintf() is often a good choice, but not always
(e.g., if the destination isn't an array, we'd have to get the size from
somewhere else).
I wouldn't be surprised if there's a way to ask coccinelle to convert
the easy cases and barf with an error on the hard cases or something. I
don't know the tool very well.
-Peff
next prev parent reply other threads:[~2018-07-13 21:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 20:43 [PATCH] blame: prefer xsnprintf to strcpy for colors Jeff King
2018-07-13 20:58 ` Stefan Beller
2018-07-13 21:04 ` Jeff King [this message]
2018-07-13 21:10 ` Stefan Beller
2018-07-13 21:29 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180713210452.GA18909@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).