All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Curl Project Removes strncpy() and strcpy() Functions for Security and Code Safety

By

firesteelrain

5mo ago· 4 min readenInsight

Summary

The article discusses the curl project's decision to eliminate both strncpy() and strcpy() functions from their source code due to security concerns and poor API design. The author explains that strncpy() is problematic because it might not null-terminate strings and pads buffers with zeroes, while strcpy() lacks bounds checking. The article advocates for using safer alternatives like snprintf() or custom wrapper functions that ensure proper string handling and error checking.

Key quotes

· 4 pulled
strncpy() is a weird function with a crappy API. It might not null terminate the destination and it pads the target buffer with zeroes.
Quite frankly, most code bases are probably better off completely avoiding it because each use of it is a potential mistake.
In that particular rewrite when we made strncpy calls extinct, we made sure we would either copy the full string properly or return error.
It is rare that copying a partial string is the right thing to do.
Snippet from the RSS feed
Some time ago I mentioned that we went through the curl source code and eventually got rid of all strncpy() calls. strncpy() is a weird function with a crappy API. It might not null terminate the destination and it pads the target buffer with zeroes. Quit

You might also wanna read