Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

Illusions of Safety


TR 24731 and Safety

The functions in TR 24731 are useful in some situations. They're not the ultimate answer to the problem of buffer overruns. As always, careful design, thorough testing, and code reviews are the steps needed to write fast, robust, and correct applications.

Notes

  1. [1] Officially, that's ISO/IEC TR 24731, "Information Technnology—Programming languages, their environments and system software interfaces—Specification for Safer, More Secure C Library Functions." It's still being worked on, so it's a draft and not a final document. You can get a copy at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1135.pdf.
  2. [2] It also provides functions that, unlike their Standard C counterparts, can be called from multiple threads without worrying about one call overwriting static data in use by another thread. But that's a subject for a different column.
  3. [3] When Borland was working on its first compiler that supported Windows, we had a mysterious crash in one of the programming examples from Microsoft's Windows SDK. The program ran fine with Microsoft's compiler and library, and crashed with ours. Since our compiler and library were incomplete, we naturally focused on them. But it turned out that the problem was in the example, which had a buffer overrun.
  4. Borland's compiler arranged auto variables in a different order than Microsoft's did, turning this symptom-free overrun into a program crash.
  5. [4] Commodore 64 programmers should recognize this technique. It's how we did assembly language programming from BASIC—stuff opcodes into an array and jump. Tedious, but it worked.
  6. [5] But intermediate functions shouldn't have an assert to check the length of the string. There's nothing to be gained by testing there, since the function that does the copy will make the debugging check.

DDJ


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.