HNHacker News
TopNewBestAskShowJobs

rseacord

560 karma · joined March 29, 2020

Robert Seacord is a Technical Director at NCC Group where he researches and teaches secure coding in C, C++, Java, and other languages. Seacord founded the secure coding initiative in the CERT Division of Carnegie Mellon University's Software Engineering Institute (SEI) and was an adjunct professor in the School of Computer Science and the Information Networking Institute at Carnegie Mellon University and at the University of Pittsburgh. He is an expert on ISO/IEC JTC1/SC22/WG14, the international standardization working group for the programming language C. He is also the author of six previous books, including The CERT C Coding Standard, Second Edition (2014), Secure Coding in C and C++, Second Edition (2013), The CERT Oracle Secure Coding Standard for Java (2011), and Java Coding Guidelines: 75 Recommendations for Reliable and Secure Programs (2014). Robert Seacord is on the Advisory Board for the Linux Foundation.
submissionscomments
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
None that I'm aware of.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
My idea was to add something like the GoLang defer statement to C (as a function with some special compiler magic). The following is an example of how such a function could be used to cleanup allocated resources regardless of how a function returned:

  int do_something(void) {
    FILE *file1, *file2;
    object_t *obj;
    file1 = fopen("a_file", "w");
    if (file1 == NULL) {
      return -1;
    }
    defer(fclose, file1);
  
    file2 = fopen("another_file", "w");
    if (file2 == NULL) {
      return -1;
    }
    defer(fclose, file2);

    obj = malloc(sizeof(object_t));
    if (obj == NULL) {
      return -1;
    }
    // Operate on allocated resources
    // Clean up everything
    free(obj);  // this could be deferred too, I suppose, for symmetry 
  
    return 0;
  }
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
Take a look at N2466 2020/02/09 Svoboda, Towards Integer Safety which has some support in the committee:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2466.pdf

(signal is a strong word... maybe indicate?)

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
yes, that is correct.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
There was a proposal for a checked integer type that you might want to look at:

N2466 2020/02/09 Svoboda, Towards Integer Safety

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2466.pdf

The committee asked the proposers for further work on this effort.

Integer types that saturate are an interesting idea. Because signed integer overflow is undefined behavior, implementations are not prohibited from implementing saturation or trapping on overflow.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
A full list of proposals to WG14 can be found here:

http://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log...

These papers are usually quite interesting.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
Good question, but not at all! I've been working as hard as I can for the past 15 years to improve C Language security as have other security-minded members of the committee. Generally speaking, we are in the minority as performance is still the major driver for the language. Any security solution that introduces > 5% overhead, for example, is a nonstarter. I think we all understand that are jobs are completely safe no matter what security improvements we can get adopted.

The committee works a lot lobbyist. A minority of people with a large financial interest in the technology (such as compiler writers) have undue influence because they participate in the process. I always encourage C language users to take a more active role, but they usually don't. Cisco is an example of user community that actively takes part in C Standardization.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
I think we are always looking at ways to "clean up C" but that this has to be done very carefully not to break existing code. For example, the committee recently voted to remove support for function definitions with identifier lists from C2x http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2432.pdf At least one vendor was not very happy with this decision.

Undefined behaviors tend to be undefined for a reason and shouldn't be thought of as defects in the standard. In my years on the committee, I have always argued to define as much behavior as possible and to as narrowly define undefined behaviors as possible.

We also had a recent discussion about adding additional name spaces (when discussing reserved identifiers), but it didn't gain much traction.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
Maybe someone else can respond to this as well, but I feel like the primary reason signed overflow is still undefined behavior is because so many optimizations depend upon the undefined nature of signed integer overflow. My advice has always been to use unsigned integer types when possible.

Personally, I would like to get rid of many of the trap representations (e.g., for integers) because there is no existing hardware in many cases that supports them and it gives implementers the idea that uninitialized reads are undefined behavior.

On the other hand, I just wrote a proposal to WG14 to make zero-byte reallocations undefined behavior that was unanimously accepted for C2x.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
I can't imagine it will ever be changed, since this would be a breaking change to the language.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
I don't think we'll ever deprecate char, int, long, float, double, or size_t. ssize_t is not part of the C Standard, and hopefully never will be as it is a bit of an abomination. The main driver behind the evolution of the C Standard is not to break existing code written in C, because the world largely runs on C programs.

C does provide fixed width types like uint8_t, uint16_t, uint32_t, and uint64_t. These are optional types because they can't be implemented on implementations that don't have the appropriate word sizes. We also have required types such as

uint_least16_t uint_least32_t uint_least64_t uint_least8_t

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
C also has renewed interest around IoT programming and mobile devices
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
The results (from the minutes http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2377.pdf)

6.33 Sebor, Add strnlen to C2X [N 2351] Result: No consensus on putting N2351 into C2X.

6.34 Sebor, Add stpcpy, and stpncpy to C2X [N 2352] Result: No consensus to put N2352 into C2X.

6.35 Sebor, Add strdup and strndup to C2X [N 2353] Result: N2353 be put into C2X. The committee wants a proposal for the wide character versions of any POSIX functions voted in this meeting.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
There were a number of recent proposals to adopt various POSIX functions by Martin Sebor into C including:

  N2353 2019/03/17 Sebor, Add strdup and strndup to C2X
  N2352 2019/03/17 Sebor, Add stpcpy, and stpncpy to C2X
  N2351 2019/03/17 Sebor, Add strnlen to C2X
He is lurking on this thread as well. These proposals can all be found in the document log at http://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log...
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
No one has proposed making these standard. I doubt they would gain much support as they are similar to the Annex K Bounds Checked Interface functions strcpy_s and strcat_s but not quite as good IMHO.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
I would say no, that we are still adding new features. Aaron Ballman was responsible for adding attributes to the C2x (he can tell you more). We're also looking at #embed feature to incorporate binaries the way that #include incorporates text.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
C is a pretty well established language, so this question should probably be asked the other way around. C was primarily designed to complete with FORTRAN.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
So what do people think about having a feature in the C language akin to the defer statement in GoLang?

The GoLang defer statement defers the execution of a function until the surrounding function returns. The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns. It looks like an interesting mechanism for cleaning up resources.

rseacord··on Tell HN: C Experts Panel – Ask us anything about C
It's a longish story, but people do seem to like the cover. We started equating the idea of C == Sea, so we had some early drawings of the robot riding various undersea creatures including a giant squid. I thought that looked overly phallic, so I suggested the robot ride Cthulhu instead, an unofficial mascot of NCC Group.
rseacord··on Tell HN: C Experts Panel – Ask us anything about C
Nothing to it! Just hit the reply button on comments you want to respond to. You can also upvote anything you like by clicking on the up arrow to the left of the comment.
rseacord··on Effective C: An Introduction to Professional C Programming
So there are many ideas here. I commented separately that I would be happy to help members of the community develop quality proposals and champion these to the committee. You can look here http://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log... to see what proposals normally look like. You would have to develop your suggestions further before they would have a reasonable chance of being adopted.
rseacord··on Effective C: An Introduction to Professional C Programming
This is an interesting coincidence, because I just started drafting a 'defer' paper. In general, this is not an abuse of my position. I would be happy to collaborate with you (or anyone else in the community) to develop papers and champion them to the committee. They would have to be sensible ideas, which both of yours are too.
← PreviousPage 2 of 2