git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] introduce "banned function" list

From
Jeff King <peff@peff.net>
Date
Jul 20, 2018, 00:54 UTC
Message-ID
<20180720005404.GA2179@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kaqgF5zNC0X5+EnuPhYiaav9JiSsgeXF=deryS3sKYq2A@mail.gmail.com>
On Thu, Jul 19, 2018 at 02:47:35PM -0700, Stefan Beller wrote:
Show 9 quoted lines
> > But that may be overly paranoid.  Once upon a time there was some rules
> > lawyering around CodingGuidelines, but I think that was successfully
> > shut down and hasn't reared its head for several years.
> 
> Heh; My preference would be to keep docs as short and concise as
> possible (and lawyering sounds like "verbosity is a feature" :-P) but
> still giving advice on controversial (i.e. not enforced by a machine in
> a deterministic fashion) things such as having braces around one
> statement for example or leaving them out.

I think we literally had somebody say "I don't have to abide by this in a review because it wasn't in CodingGuidelines." But then, that is perhaps indicative of other problems.

Show 5 quoted lines
> So maybe I would have rather asked, why we start out with these two
> functions. And you seem to call them "obviously bad", and you take both
> of them because they need to be handled differently due to the variadic macros.
> (And those two are "obviously worse" than strcat, as they are used more often.
> But strcat, being on MS ban list[1], would do just as fine)
Ooh, strcat is another one that should be added.

I actually thought about splitting it into three commits (introduce mechanism, then one per function), but it felt like stringing it out. You are probably right, though, that each function deserves its own explanation. And the commit message is already quite long.

Show 8 quoted lines
> >   We'll include strcpy() and sprintf() in the initial list of banned
> >   functions. While these _can_ be used carefully by surrounding them
> >   with extra code, there's no inherent check that the size of the
> >   destination buffer is big enough, it's very easy to overflow the
> >   buffer.
> 
> Sounds good to me, maybe even add "We've had problems with that
> in the past, see 'git log -S strcpy'", but that may be too much again.

Actually, that's a good point. We've had actual bugs due strcpy(). I can similarly point to bad uses of strcat().

I think I have sufficient fodder for a re-roll along these lines (assuming we like the idea at all; Junio seemed to have some reservations, but I'll reply there separately).

-Peff
Previous: Stefan BellerNext: Junio C Hamano
Message 10 of 42 in “fail compilation with strcpy”
  1. 0/2 fail compilation with strcpyJeff King, Jul 19, 2018
  2. 1/2 introduce "banned function" listJeff King, Jul 19, 2018
  3. Eric SunshineJul 19, 2018
  4. Jeff KingJul 19, 2018
  5. Eric SunshineJul 19, 2018
  6. Jeff KingJul 20, 2018
  7. Stefan BellerJul 19, 2018
  8. Jeff KingJul 19, 2018
  9. Stefan BellerJul 19, 2018
  10. Jeff KingJul 20, 2018
  11. Junio C HamanoJul 19, 2018
  12. Randall S. BeckerJul 19, 2018
  13. Jeff KingJul 20, 2018
  14. Jeff KingJul 20, 2018
  15. Junio C HamanoJul 20, 2018
  16. Jeff KingJul 20, 2018
  17. Theodore Y. Ts'oJul 20, 2018
  18. Jeff KingJul 20, 2018
  19. Junio C HamanoJul 20, 2018
  20. Derrick StoleeJul 20, 2018
  21. Duy NguyenJul 20, 2018
  22. Elijah NewrenJul 20, 2018
  23. Jeff KingJul 20, 2018
  24. Jeff KingJul 20, 2018
  25. 2/2 banned.h: mark strncpy as bannedJeff King, Jul 19, 2018
  26. Ævar Arnfjörð BjarmasonJul 19, 2018
  27. Jeff KingJul 19, 2018
  28. Junio C HamanoJul 20, 2018
  29. Jeff KingJul 20, 2018
  30. Junio C HamanoJul 20, 2018
  31. 0/4 fail compilation with strcpyJeff King, Jul 24, 2018
  32. 1/4 automatically ban strcpy()Jeff King, Jul 24, 2018
  33. Eric SunshineJul 24, 2018
  34. Jeff KingJul 26, 2018
  35. 1/4 automatically ban strcpy()Jeff King, Jul 26, 2018
  36. Junio C HamanoJul 26, 2018
  37. Jeff KingJul 27, 2018
  38. Junio C HamanoJul 27, 2018
  39. Jeff KingJul 28, 2018
  40. 2/4 banned.h: mark strcat() as bannedJeff King, Jul 24, 2018
  41. 3/4 banned.h: mark sprintf() as bannedJeff King, Jul 24, 2018
  42. 4/4 banned.h: mark strncpy() as bannedJeff King, Jul 24, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.