news.volyx.in

Banned C standard library functions in Git source code (github.com)

502 points by susam · 2611 days ago · 312 comments on HN

Article summary

The Git source code bans certain C standard library functions due to potential security risks. These functions include strncpy, which does not guarantee null-termination of the destination string. The ban is intended to prevent common errors that can lead to security vulnerabilities. The use of these functions is discouraged in favor of safer alternatives.

Main themes

  • C standard library functions
  • security risks
  • portability
  • compiler compatibility
  • string handling

What commenters say

  • Using GCC-specific attributes and extensions can be limiting for portability and compatibility with other compilers.
  • The ban on certain C standard library functions is a responsible decision to prevent common security risks and errors.
  • Some functions, like strlcpy, are considered safer alternatives, but their use is not universally adopted due to limitations and compatibility issues.
  • The use of functions like strncpy can lead to security vulnerabilities due to the lack of guaranteed null-termination of the destination string.
  • The C standard library lacks a sensible and portable replacement for certain functions, leading to the use of workarounds or non-standard functions.
  • Some commenters argue that the use of C++ or other languages can provide better security and improvements, but this is not always a feasible solution.
  • Others argue that certain functions, like strlcpy, are not inherently broken or unsafe, but rather require careful use and consideration of their limitations.