public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions
@ 2010-11-17  0:53 noloader at gmail dot com
  2010-11-17  1:08 ` [Bug c++/46513] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: noloader at gmail dot com @ 2010-11-17  0:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

           Summary: Request: Warning for use of unsafe string handling
                    functions
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: noloader@gmail.com


Hi All,

The security minded folks of Linux [1,2], Apple [3], Microsoft [4], and
C/C++[5] agree that the original string handling functions are lacking or
deficient (i.e., "unsafe). Most surprising is that a diverse and disparate
group can unanimously agree on anything.

I often review internal code, GNU/FSF code, and open source code which
regularly uses unsafe functions. As one commenter stated on
{BugTraq|FunSec|FullDisclosure} (can't find the reference at the moment).
"there is no reason to be using strcpy in 2010".

The comment on the mailing list might indicate a larger problem: some folks are
not aware that some of these functions are unsafe and/or dangerous, and should
not be used. Consider: how many times have you seen copy/paste code that uses
an unsafe function *AND* offers a security statement or warning about it use?

A warning switch - perhaps part of "-Wextra" - would be very useful for the
following functions (with the Linux/Unix suggested replacement) since
replacements are readily available on all platforms.

strcat -> strlcat
strcpy -> strlcpy
strncat -> strlcat
strncpy -> strlcpy
sprintf -> snprintf
vsprintf -> vsnprint

Jeffrey Walton
Baltimore, MD, US

[1] Graff and van Wyk. Secure Coding: Principles & Practices,
http://www.securecoding.org/
[2] Wheeler. Secure Programming for Linux and Unix HOWTO - Creating Secure
Software, http://www.dwheeler.com/secure-programs/
[3] Apple, Inc. Secure Coding Guide,
http://developer.apple.com/library/mac/#documentation/Security/Conceptual/SecureCodingGuide/Introduction.html
[4] Howard and LeBlanc. Writing Secure Code,
http://www.microsoft.com/learning/en/us/book.aspx?ID=5957
[5] Seacord. Secure Coding in C and C++,
http://www.cert.org/books/secure-coding/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
@ 2010-11-17  1:08 ` redi at gcc dot gnu.org
  2010-11-17  1:25 ` noloader at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-17  1:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-17 00:53:47 UTC ---
The maintainers of GNU libc, the C and C++ committees and the POSIX working
group have not seen fit to include those functions, and they're not available
on my GNU/Linux box.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
  2010-11-17  1:08 ` [Bug c++/46513] " redi at gcc dot gnu.org
@ 2010-11-17  1:25 ` noloader at gmail dot com
  2010-11-17  3:21 ` noloader at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: noloader at gmail dot com @ 2010-11-17  1:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

--- Comment #2 from Jeffrey Walton <noloader at gmail dot com> 2010-11-17 01:08:22 UTC ---
Hi Jonathan,

(In reply to comment #1)
> The maintainers of GNU libc, the C and C++ committees and the POSIX working
> group have not seen fit to include those functions, and they're not available
> on my GNU/Linux box.
Interesting. In 2010, I was hoping the strl* functions would side step the
political mess of TR24731-1 on *nix. For those resisting, TR24731-1 is now a
normative part of the C1x draft (as Annex K), so its coming whether they want
it or not :/

Never the less, a warning would still be useful since lots of code still
employs the unsafe functions. For those who are inclined - such as myself and
others who perform security related audits - a compiler warning would be a
welcome addition, even if there is no standard replacement. I'll tackle "what
to replace it with" in-turn on the specific platform.

Jeff


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
  2010-11-17  1:08 ` [Bug c++/46513] " redi at gcc dot gnu.org
  2010-11-17  1:25 ` noloader at gmail dot com
@ 2010-11-17  3:21 ` noloader at gmail dot com
  2010-11-17  5:40 ` noloader at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: noloader at gmail dot com @ 2010-11-17  3:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

--- Comment #3 from Jeffrey Walton <noloader at gmail dot com> 2010-11-17 02:04:14 UTC ---
(In reply to comment #1)
> The maintainers of GNU libc, the C and C++ committees and the POSIX working
> group have not seen fit to include those functions, and they're not available
> on my GNU/Linux box.

Indeed. Below is from "Secure Portability" by Damien Miller
(http://www.openbsd.org/papers/portability.pdf).

I know "finding the replacement" is not a GCC issue, but perhaps folks who need
to the *nix safe string gear can use TR24731-2 (not TR24731-1), which is POSIX
and includes strl* and friends.

And to reiterate: the warning would be useful. Miller states [in 1995] over 100
projects are *NOT* using strcpy and friends. So there are at least 100 projects
(plus me) who would likely use the switch ;). The number would only grow as
other security minded folks became aware of the GCC functionality.

Jeff

The strlcpy and strlcat API properly check the target buffer’s bounds,
nul-terminate in all cases and return the length of the source string, allowing
detection of truncation. This API has been adopted by most modern operating
systems and many standalone software packages, including OpenBSD (where it
originated), Sun Solaris, FreeBSD, NetBSD, the Linux kernel, rsync and the
GNOME project. The notable exception is the GNU standard C library, glibc [12],
whose maintainer steadfastly refuses to include these improved APIs, labelling
them “horribly inefficient BSD crap” [4], despite prior evidence that they are
faster is most cases than the APIs they replace [13]. As a result, over 100 of
the software packages present in the OpenBSD ports tree maintain their own
strlcpy and/or strlcat replacements or equivalent APIs - not an ideal state of
affairs.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
                   ` (2 preceding siblings ...)
  2010-11-17  3:21 ` noloader at gmail dot com
@ 2010-11-17  5:40 ` noloader at gmail dot com
  2010-11-17 10:47 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: noloader at gmail dot com @ 2010-11-17  5:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

--- Comment #4 from Jeffrey Walton <noloader at gmail dot com> 2010-11-17 03:49:44 UTC ---
(In reply to comment #2)
> Hi Jonathan,
> 
> (In reply to comment #1)
> > The maintainers of GNU libc, the C and C++ committees and the POSIX working
> > group have not seen fit to include those functions, and they're not available
> > on my GNU/Linux box.
> Interesting. In 2010, I was hoping the strl* functions would side step the
> political mess of TR24731-1 on *nix. For those resisting, TR24731-1 is now a
> normative part of the C1x draft (as Annex K), so its coming whether they want
> it or not :/
I stand corrected: C1X draft dated 2010-10-04 now includes the bounds checking
interfaces. See "C1X Draft",
http://www.open-std.org/Jtc1/sc22/wg14/www/docs/n1516.pdf at
http://www.open-std.org/Jtc1/sc22/wg14/www/projects.

So in addition to [nearly ubiquitous] support for strlcpy and friends, we will
have strcpy_s and friends.

Jeff


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
                   ` (3 preceding siblings ...)
  2010-11-17  5:40 ` noloader at gmail dot com
@ 2010-11-17 10:47 ` redi at gcc dot gnu.org
  2010-11-17 11:51 ` joseph at codesourcery dot com
  2020-05-19 20:40 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-17 10:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-17 10:43:51 UTC ---
(In reply to comment #3)
> I know "finding the replacement" is not a GCC issue, but perhaps folks who need
> to the *nix safe string gear can use TR24731-2 (not TR24731-1), which is POSIX
> and includes strl* and friends.

TR24731-2 does include functions from POSIX, but the only string handling ones
in n1337 are strdup and strndup, not strl* - and I might be wrong but I don't
know of any plans to add strl* to POSIX.

Besides, anything in C1x will not make it into a C++ standard for many years,
we're still trying to get C++0x finished and new features won't be added now. 
Maybe this request should be for the C front end?
Otherwise you're requesting warnings in C++ code about functions for which
there are no portable, standardised alternative available.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
                   ` (4 preceding siblings ...)
  2010-11-17 10:47 ` redi at gcc dot gnu.org
@ 2010-11-17 11:51 ` joseph at codesourcery dot com
  2020-05-19 20:40 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: joseph at codesourcery dot com @ 2010-11-17 11:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

--- Comment #6 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2010-11-17 11:50:16 UTC ---
On Wed, 17 Nov 2010, noloader at gmail dot com wrote:

> I stand corrected: C1X draft dated 2010-10-04 now includes the bounds checking
> interfaces. See "C1X Draft",
> http://www.open-std.org/Jtc1/sc22/wg14/www/docs/n1516.pdf at
> http://www.open-std.org/Jtc1/sc22/wg14/www/projects.
> 
> So in addition to [nearly ubiquitous] support for strlcpy and friends, we will
> have strcpy_s and friends.

I can't imagine glibc will want to have that set of functions in libc - I 
expect it will simply omit that optional set of interfaces and not define 
__STDC_LIB_EXT1__.  Maybe someone will write a glibc add-on putting them 
in a separate library that a handful of people might then use.

*Some* of the functions there are useful, but the notion that tmpfile (for 
example) has security issues requiring tmpfile_s is nonsense.  And the 
main utility of most of those functions is to retrofit security 
improvements to old code without understanding it.  glibc has its own 
means for such retrofitting (in particular _FORTIFY_SOURCE).  In both 
cases they are really a matter of reducing the risk from certain kinds of 
bugs rather than fixing them; to fix them, you need actually to understand 
the code and determine when you should avoid arbitrary limits and allocate 
as much memory as needed (taking care about overflow when calculating 
allocation sizes) and when you should impose limits and how you should 
handle overflow of them (quietly truncating is not generally a good 
approach); safer interfaces and _FORTIFY_SOURCE should then be used *on 
top of* proper design and calculation of allocations, to reduce the risk 
of any remaining bugs, rather than as a substitute for avoiding the 
possibility of overflow or truncation in the first place.

If you wish to enforce a coding standard disallowing certain functions in 
a particular code base, you are free to use existing GCC features such as 
"#pragma GCC poison" and the "deprecated" attribute.  That seems better to 
me than GCC embedding particular assumptions about a particular set of 
functions, when everyone will have their own preferences about what 
functions should be used and whether functions are safe in a given code 
base depends on how it uses them.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/46513] Request: Warning for use of unsafe string handling functions
  2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
                   ` (5 preceding siblings ...)
  2010-11-17 11:51 ` joseph at codesourcery dot com
@ 2020-05-19 20:40 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-19 20:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46513

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
Resolved as Won't Fix per comment #1 and others.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-05-19 20:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-17  0:53 [Bug c++/46513] New: Request: Warning for use of unsafe string handling functions noloader at gmail dot com
2010-11-17  1:08 ` [Bug c++/46513] " redi at gcc dot gnu.org
2010-11-17  1:25 ` noloader at gmail dot com
2010-11-17  3:21 ` noloader at gmail dot com
2010-11-17  5:40 ` noloader at gmail dot com
2010-11-17 10:47 ` redi at gcc dot gnu.org
2010-11-17 11:51 ` joseph at codesourcery dot com
2020-05-19 20:40 ` msebor at gcc dot gnu.org

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).