Linux eliminates the strncpy API after six years of work, 360 patches

phoronix.com

115 points by simonpure 7 hours ago


https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

WalterBright - 2 hours ago

"The strncpy function within the Linux kernel has been a "persistent source of bugs" for years due to counter-intuitive semantics and behavior around NUL termination along with performance issues due to redundant zero-filling of the destination."

Huh. Whenever I've been asked to review C code, I always looked for strncpy and always found a bug with it.

lambdaone - 3 hours ago

This sort of boring grind is where the real work of systems engineering is done. Big infrastructure projects like this work on making the Linux kernel more reliable while still keeping it workable throughout the process move on the scale of decades, not months.

twothreeone - an hour ago

wow, very humbling. I'm actually amazed how many people contributed to this. It's easy to get attribution for "cool new features", but arguable removing bad features is even more important for something as fundamental as the kernel. Cudos!

I'm sure these are the sorts of things that will go down as folklore from the "founding ages", when everyone will have forgotten how to understand source code in 50 years and the Claude/Codex cruft just silently keeps piling on and burning the majority of our planets energy.

senfiaj - 4 hours ago

I wonder, why not use a string buffer paired with its length? For example, maybe use struct that has char pointer, and 2 ints (occupied length + total buffer length). Almost like c++'s std::string. This null terminator thing really sucks, it's potentially insecure and often unperformant.

mrlonglong - 6 hours ago

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

D-Coder - 3 hours ago

Note that "360 Patches" is 360 uses of strncpy that have been removed, not necessarily bugs.

PlunderBunny - 6 hours ago

I worked on a Win32 app that used space-padded strings, i.e. the destination string was padded with spaces, but there was still a null on the last byte. You had to use special versions of the string functions for length, copy etc.

I’m not sure why this was - the source base was so old it might have had its origins in Pascal struct behaviour.

jibal - an hour ago

The purpose of strncpy, which was originally part of the UNIX kernel code, was to copy file names to and from directory entries that consisted of a 2 byte inode number and a 14 byte zero-padded but not zero-terminated name field.

I started warning my colleagues against using it the moment I saw it for the first time about 50 years ago.

devsda - 2 hours ago

Did anybody else misunderstand the title as removing strncpy func for linux users ?

For a moment, I misunderstood it as (g)libc removing strncpy and was worried about the trouble its going to cause.

naturalmovement - 5 hours ago

A reminder that we've had strlcpy[1] for ~ 30 years but it was never accepted into the Linux world because of typical petty open source bullshit. This is why we can't have nice things.

[1] https://man.openbsd.org/strlcpy

qarl - 2 hours ago

Am I going to be the first person to ask this after five hours? Really?

Wouldn't this work be extremely easy to implement with an LLM coder?

larodi - 6 hours ago

Wonder when is someone going to brave and fork the linux kernel and try to ffwd it with automatic programming.

Animats - 2 hours ago

This is a job for Claude!

What happens if you turn a job like that over to Claude Code? A mess? Good results? Code bloat? Worth trying on existing C programs.