Linux 7.2 Closes Memory Bug Class With strncpy Removal After Six Years

Linux kernel strncpy removed in Linux 7.2 after 362 patches and six years of coordinated work. The dangerous C string function leaked kernel memory through unterminated buffers and wasted CPU cycles...

Tech Times
Linux kernel 清完 strncpy() 了

看到 Linux kernel 清完 strncpy 的消息了:「Linux Finally Eliminates The strncpy API After Six Years Of Work, 360+ Patches (via)」。 Linux 7.2 會是第一個 strncpy-free 的版本: Linux 7.2 has finally eliminated the strncpy API from the Linux kernel.

Gea-Suan Lin's BLOG

The string copying API #strncpy was finally removed from #Linux for #LinuxKernel 7.2 via these changes submitted by @kees:

https://git.kernel.org/torvalds/c/1a3746ccbb0a97bed3c06ccde6b880013b1dddc1

He also removed the fuction itself:

https://git.kernel.org/torvalds/c/079a028d6327e68cfa5d38b36123637b321c19a7

To quote: ""strncpy() has been a persistent source of bugs due to its ambiguous intended usage and frequently counter-intuitive semantics: it may not NUL-terminate the destination, and it unconditionally zero-pads to the full length, which isn't always needed. All former callers have been migrated to: […] https://github.com/KSPP/linux/issues/90"

For some of the problems of this API, see the following great @lwn articles:

* strscpy() and the hazards of improved interfaces – https://lwn.net/Articles/659214/
* Ushering out strlcpy() – https://lwn.net/Articles/905777/
* Better string handling for the kernel – https://lwn.net/Articles/948408/

#Kernel

RE: https://mastodon.social/@bagder/115805010608994033

Qué interesante este post de @bagder sobre el uso de #strcpy vs #strncpy en C.

Siempre vi que la recomendación era usar strncpy en vez de strcpy.

El problema de strcpy es que no controla los límites de buffers, mientras que strncpy sí, pero a la vez, tiene sus propios problemas.

El uso de #snprintf me parece interesante como reemplazo, o directamente una implementación manual como la que se plantea con curlx_strcopy.

BTW, qué ganas tengo de programar en #C ahora xD

#linux #curl #dev

🚨 Breaking News: "Programmer discovers #strncpy is bad! 🎉" In a shocking revelation, it turns out using a function that doesn't null-terminate strings can lead to problems. Who would have thought? Next, Daniel plans to tackle the #mysteries of 'printf' – stay tuned! 🤔
https://daniel.haxx.se/blog/2025/12/29/no-strcpy-either/ #BreakingNews #ProgrammerProblems #Issues #printf #HackerNews #ngated
no strcpy either

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. Quite frankly, most code bases are probably better off completely … Continue reading no strcpy either →

daniel.haxx.se