From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752036AbbJELyB (ORCPT ); Mon, 5 Oct 2015 07:54:01 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:32799 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbbJELx7 (ORCPT ); Mon, 5 Oct 2015 07:53:59 -0400 Date: Mon, 5 Oct 2015 13:53:55 +0200 From: Ingo Molnar To: Linus Torvalds Cc: Chris Metcalf , open list , Peter Zijlstra , Thomas Gleixner , "H. Peter Anvin" , Borislav Petkov Subject: Re: [PATCH] string: Improve the generic strlcpy() implementation Message-ID: <20151005115355.GA27073@gmail.com> References: <55F1DD53.1070102@ezchip.com> <20151005112700.GA1096@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151005112700.GA1096@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Ingo Molnar wrote: > 2) > > Another problem is that strlcpy() will also happily do bad stuff if we pass > it a negative size. Instead of that we will from now on print a (one time) > warning and return safely. Hm, so this check is buggy, as 'size_t' is unsigned - and for some reason GCC didn't warn about the never-met comparison and the resulting unreachable dead code here: > + /* Overflow check: */ > + if (unlikely(dest_size < 0)) { > + WARN_ONCE(1, "strlcpy(): dest_size < 0 underflow!"); > + return strlen(src); > + } which is annoying. Would people object to something like: > + /* Overflow check: */ > + if (unlikely((ssize_t)dest_size < 0)) { > + WARN_ONCE(1, "strlcpy(): dest_size < 0 underflow!"); > + return strlen(src); > + } ? As I doubt it's legit to have larger than 2GB strings. Also, I'm wondering why GCC didn't warn. Thanks, Ingo