Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422704AbbD2IYw (ORCPT ); Wed, 29 Apr 2015 04:24:52 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:35707 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031697AbbD2IYi (ORCPT ); Wed, 29 Apr 2015 04:24:38 -0400 MIME-Version: 1.0 In-Reply-To: <20150429003514.GL889@ZenIV.linux.org.uk> References: <20150428034859.GI889@ZenIV.linux.org.uk> <1363736428.511175.1430199310500.open-xchange@webmail.nmp.proximus.be> <20150428160523.GJ889@ZenIV.linux.org.uk> <553FE3F0.4060803@ezchip.com> <553FFDE9.9070700@ezchip.com> <20150429003514.GL889@ZenIV.linux.org.uk> Date: Wed, 29 Apr 2015 10:24:37 +0200 X-Google-Sender-Auth: 5-QT8oNJkNL4wQnzzRTFnqXX6VE Message-ID: Subject: Re: revert "fs/befs/linuxvfs.c: replace strncpy by strlcpy" From: Geert Uytterhoeven To: Al Viro Cc: Linus Torvalds , Chris Metcalf , Fabian Frederick , Linux Kernel Mailing List , Randy Dunlap , Rickard Strandqvist Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1385 Lines: 29 On Wed, Apr 29, 2015 at 2:35 AM, Al Viro wrote: > strncpy() has another use, though, and it can't be replaced by strlcpy() - > see the commits that had started this thread. IMO they (and anything > else of the same nature) really need to be reverted; using strlcpy() on > something that isn't guaranteed to be NUL-terminated is a serious bug. To be honest, I never considered the "source is not NUL-terminated" case. Strings in C (if they are strings, and not "buffers"; with buffers you should know how many bytes are valid anyway) are always terminated ;-) The other case we sometimes do want strncpy() for is the "crazy "fill with NUL" at the end" feature, to avoid leaking sensitive data. The alternative is to clear the target first, or the remainder afterwards. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/