4 ms·
Annex K has never been non-optional. No one has ever implemented a full compliant Annex K, and it's a terrible abstraction. It predates basic static analysis
by loeg 7y ago
Annex K has never been non-optional. No one has ever implemented a full compliant Annex K, and it's a terrible abstraction. It predates basic static analysis and suffers from more or less the same problems as non-Annex K variants. E.g., if you pass in the wrong buffer length to the K variant, you still get buffer overflows. How do you tell if the wrong length is passed? Static analysis. The same analyzers work with existing libc functions. I do think C or at least POSIX should have adopted strlcpy and strlcat, though; strncpy doesn't do what most people think it does.
Source, and more info: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm
- pjmlp 7y agoI got that wrong, thanks for correcting me. I do agree that Annex K doesn't provide a proper solution, as data and length keep being separated. However what I disagree is the way it was left to rotten without adoption, instead of actually fixing it. Static analysis is not a solution, given that all surveys point out that only a minority cares to actually make use of them, or works in environments where they are welcomed, with supportive toolchains. Also they don't work across third party binary dependencies, heavily used in the corporate environments. So unwillingness to improve C language security in the standard shows how little those driving WG 14 care about security. At least C11 made VLAs optional, which never were a good idea to start with.
- loeg 7y agoI'm not saying static analysis is a complete solution, just that Annex K doesn't actually function without it. I.e., any criticism you want to leverage at static analysis also applies to Annex K. (The compiler is one form of static analysis that users can't really get away from, though. Users can turn all the warnings off, but only the extremely novice or foolhardy do so.) I agree letting Annex K hang out optionally in the standard isn't especially useful; in its current form it should be removed. It isn't clear how it would be "fixed" without being something completely different from Annex K. Unfortunately, C hasn't had an actual language update since C11; C18 was just a clarification and errata incorporation update. The C2x committee is in progress but hasn't yet made any binding decisions on formal language changes, AFAIK. I don't know that 3rd party binary dependencies are heavily used in corporate environments. I find that a little difficult to believe. I work in an enterprise environment with a huge codebase and we have no 3rd party binary libraries. We have a number of 3rd party open source or NDA source libraries, but we can and do use static analysis on them. It would be impossible to get to the kind of reliability numbers essential to our business with unauditable, unfixable 3rd party code in our product. WG 14 don't view bounded string copying as some core part of the language, I think. The C standard is about providing a minimal definition of a portable abstract machine; this leaves implementors or more concrete standards, like POSIX, free to provide their own safe abstractions. Quite a lot of the C standard library is sort of legacy accidents that might not be put in the standard language again if reinvented today. But there is obviously a lot of motivation to retain backwards compatibility.
- pjmlp 7y agoBinary dependencies are quite common in Windows products. Problem with POSIX is that not all environments support it, and when, not always the same version. Agree with the rest of your points, though.