Live data from Hacker News

Banned C standard library functions in Git source code

github.com

61–70 of 329 posts

Re: Banned C standard library functions in Git source code

#61

musl libc (an alternative libc) provides implementations of these functions that are memory-safe. (It only works on Linux though.)

Is is not possible to provide implementations of these functions which are both safe (meaning, within human ability to use correctly) and standards-compliant, as they either don't take any size or require leaving off the null terminator when the destination buffer is full.

Re: Banned C standard library functions in Git source code

#62
post #38

Earlier quoted context omitted.

Like essentially all C programs.

What's a good library for this kind of boilerplate? A lightweight one if possible, i.e. not fucking glib

Salvatore Sanfilippo, from Redis fame, has a nice one https://github.com/antirez/sds.

Re: Banned C standard library functions in Git source code

#64

For anybody else: Why is strncpy insecure? https://stackoverflow.com/questions/869883/why-is-strncpy-in... > strncpy() doesn't require NUL termination, and is therefore susceptible to a variety of exploits.

Yes. Also as mentioned in the post, strlcpy (when it's available) is safer.

Re: Banned C standard library functions in Git source code

#65

Why is there no brief explanations in this code why each function is banned?

Just to make it clear. I'm aware of the fact that these functions have security implications. Nonetheless when such decisions are made, I believe it's important to explain them—at least briefly—directly in the code itself.

With the way they are banned, you see it only as a compiler warning on implicit declaration of function (or at linking stage, if warnings are suppressed; idk what exact build process is). Afair, there is no evidence of banned.h in an error trace. So you have to look it up by yourself anyway.

They could rename them as “sorry X is unsafe and creates too much trouble” maybe, but in today’s internet “X considered harmful” is a common search query that everyone in the field is expected to know.

Re: Banned C standard library functions in Git source code

#66

That's a surprisingly small list, missing e.g. sscanf / gets / strtok / all the other "usual suspects" at least

I don't see a huge problem with strtok as long as it isn't a multi threaded program. It is not in gets territory which is literally impossible to use correctly.

I can't remember what's wrong with it, but it's responsible for about eleventy billion CVEs over the years

Re: Banned C standard library functions in Git source code

#67
post #26

I'm glad to see that setjmp() and longjmp() are still allowed. I'm just kidding by the way. For those C programmers who haven't encountered these before, it is a powerful way to do a "goto" in C. Powerful in the sense that you can jump anywhere, not limited to the same function. If it's used at all these days, it's used for exception handling. More info: https://en.wikipedia.org/wiki/Setjmp.h

You can build coroutines from them, too, which is really cool and useful.

Re: Banned C standard library functions in Git source code

#68
post #38

Earlier quoted context omitted.

Like essentially all C programs.

What's a good library for this kind of boilerplate? A lightweight one if possible, i.e. not fucking glib

libbsd has strlcat and strlcpy.

or just use snprintf everywhere.

Re: Banned C standard library functions in Git source code

#70
post #65

Earlier quoted context omitted.

Just to make it clear. I'm aware of the fact that these functions have security implications. Nonetheless when such decisions are made, I believe it's important to explain them—at least briefly—directly in the code itself.

With the way they are banned, you see it only as a compiler warning on implicit declaration of function (or at linking stage, if warnings are suppressed; idk what exact build process is). Afair, there is no evidence of banned.h in an error trace. So you have to look it up by yourself anyway. They could rename them as “sorry X is unsafe and creates too much trouble” maybe, but in today’s internet “X considered harmful…

Fair point. It seems that more and more projects use "-Werror" which causes the compilation to stop and show you exactly where the error comes from[1]. Second point is that searching for "is_a_banned_function" in the code directly points to this file.

[1] https://ideone.com/h0g8F1

Post reply on HN