Slashdot Mirror


Microsoft Open-Sources 'Checked C,' A Safer C Version (softpedia.com)

An anonymous reader writes from a report via Softpedia: Microsoft has open-sourced Checked C, an extension to the C programming language that brings new features to address a series of security-related issues. As its name hints, Checked C will add checking to C, and more specifically pointer bounds checking. The company hopes to curb the high-number of security bugs such as buffer overruns, out-of-bounds memory accesses, and incorrect type casts, all which would be easier to catch in Checked C. Despite tangible benefits to security, the problem of porting code to Checked C still exists, just like it did when C# or Rust came out, both C alternatives.

3 of 208 comments (clear)

  1. Re:What a Waste of Time by Anonymous Coward · · Score: 5, Informative

    strcpy_s is part of the C11 standard, and it was a library addition, not a language change.

  2. a pointer to VLA is a bounded pointer type by Uecker · · Score: 4, Informative

    The funny little known fact is: C99 already has a bounded pointer type: A pointer to a variable-length array.

        void foo(int N, char (*ptr)[N])
        {
            (*ptr)[N + 3] = 10; // undefined behaviour
        }

    Using the undefined-behaviour sanitizer, you can also have the compiler add automatic checks.

  3. Re:Solve the problem in hardware, have done with i by sdw · · Score: 4, Informative

    That's the right direction. Apple already has a pretty good version of it. (See below.)

    Bounds checking C like this now is weak and very, very late:
    https://gcc.gnu.org/ml/gcc/199...
    https://www.lrde.epita.fr/~aki...
    http://blog.qt.io/blog/2013/04...
    http://valgrind.org/docs/manua...
    https://en.wikipedia.org/wiki/...

    But the grand champion memory debugger is the Mac OS X standard malloc libraries. You can simply set environment variables and instantly get better debugging than most methods on all other platforms. I presume this is because Objective C/C++ is such a pain to debug that they just built in features to always be available, even for production apps.

    http://www.cocoawithlove.com/2...

    Those libraries are clever because when debugging array bounds corruption and used/free, all mallocs get their own mmapped memory block surrounded by unmapped memory. Plus writing patterns into free / allocated memory to detect writing to freed memory, etc. This is great because it triggers a system signal that debuggers can catch deterministically.

    I found and used those techniques on my last big project a couple years ago. The Windows desktop app and imaging C++ libraries were full of errors, memory corruption, struct and 32bit/64bit problems, etc. I had to do a lot of debugging and rewriting to port to Mac OS X, then a lot to solve corruption and threading issues. And found out, the hard way, what a mess the "standard" pthreads API / libraries were. Just spurred me on to switch to C++11 to have standard threads. This Mac OS X built-in debugging along with gdb made it a snap to find all of those kinds of errors, even for code meant for Android, Linux, and Windows.

    --
    Stephen D. Williams