Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1145073imu; Tue, 11 Dec 2018 13:32:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/UMMgXEyfcVtPQvl9XiEGBEIyub32PDNcP4OUr/CrdXI+ytArhLpvDIC+L6+5FugZPokPe7 X-Received: by 2002:a17:902:4d46:: with SMTP id o6mr16742070plh.302.1544563927211; Tue, 11 Dec 2018 13:32:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544563927; cv=none; d=google.com; s=arc-20160816; b=vtPDqLajWmB7cXeVjkvPD93uzQ4HinTvkH82yII+C2bTUZdbkhm/MWBHroNw8G3Smi Q+AlpJTmC2ZSx6L1gDb6EngeXJ5o5zHt6wCpDAb5XTKdUunmGT09BDde5EIFJy9tMMCE x1iFLFNPSgYD0HRYXa7TKkij3oVgkAraWQ2a9N03m2Y48boiXFXAPIIo4+IZWGK5L56z xp0KFWmvQecALvFQtSGQr0LfddzXaPAhg2hZVqce1Fnt7qFk1Lfj/BAEnd7ekLBsO5q5 iTnaRYVb0nxCcP5Pp54+PvQKmG52A0bLv1DKP0y/VyTNTrerxfyE1DpXSMfMO51oAxj2 uH2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nvPexIz5OObk805ef/jQ0clYGu09zGmAzQtkzuJX26I=; b=Ths0W/0VlRV9BQ/Oyv8JiScmD1CcOWM94aGiqL/5S2p5t0jqvY6loRmcKF+6UyOrMd vjsB39BxnjIKBiaMb+pDcSW9iG9IRO8IyLSiKoCbN14Aa6eOS5RTRlFsHOXAymKFRhks jGOXJ9HEKnji3Hj6n//Zz4loeI8KJo1tTMP73A7gTQQ1BjotMV35UzEkbwclLr3uNx+3 b4Oy59N7LRc7F+1SRQxF7jXZ9v7qByrDVfW3CiR91gDpIPFmwi2zv+e1CdI4am1g5JT3 fw+znabVVqlt9LOT0Uob4YHHMlmIFmxQPEre+m2tK4foyZmkfmba1AQskRnPFCS92DUi beEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c5si12566429pgq.434.2018.12.11.13.31.37; Tue, 11 Dec 2018 13:32:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726226AbeLKVah (ORCPT + 99 others); Tue, 11 Dec 2018 16:30:37 -0500 Received: from mga11.intel.com ([192.55.52.93]:25194 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbeLKVah (ORCPT ); Tue, 11 Dec 2018 16:30:37 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 13:30:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="117986239" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga001.jf.intel.com with ESMTP; 11 Dec 2018 13:30:33 -0800 Received: from andy by smile with local (Exim 4.91) (envelope-from ) id 1gWpbr-0003Ll-PC; Tue, 11 Dec 2018 23:30:31 +0200 Date: Tue, 11 Dec 2018 23:30:31 +0200 From: Andy Shevchenko To: Linus Torvalds Cc: thomas.preston@codethink.co.uk, Andrew Morton , Petr Mladek , Steven Rostedt , geert+renesas@glider.be, Jonathan Corbet , tcharding , Sergey Senozhatsky , Linux List Kernel Mailing , ben.dooks@codethink.co.uk Subject: Re: [PATCH 2/2] vsprintf: Stop using obsolete simple_strtoul() Message-ID: <20181211213031.GF10650@smile.fi.intel.com> References: <20181211152113.8523-1-thomas.preston@codethink.co.uk> <20181211152113.8523-3-thomas.preston@codethink.co.uk> <20181211180458.GE10650@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 11, 2018 at 10:19:08AM -0800, Linus Torvalds wrote: > On Tue, Dec 11, 2018 at 10:05 AM Andy Shevchenko > wrote: > > > > I think it's slightly more complicated, I run the following test case on glibc: > > > > uint32_t hi, lo, t; > > > > sscanf("00fafafafa0d0b0b0b0c000000", "%8x%8x%x", &hi, &lo, &t); > > > > 64-bit: > > HI: 00fafafa LO: fa0d0b0b (c000000) > > 32-bit: > > HI: 00fafafa LO: fa0d0b0b (ffffffff) > > But that's exactly the values my pseudo-code gets (well, my > "pseudo-code obviously just said > > // Now do "sign" and range checking on val > > The three sub-parts are: "00fafafa" "fa0d0b0b" and "0b0c000000" > > and the third one encounters an overflow in "long" on 32-bit, so it > turns into ~0. > > And yes, the 64-bit "long" in that third value gets truncated to > "uint32" when written to "t" (which is wht that "0b" part just gets > lost. > > And that's just because of historical C scanf behavior. There's no > overflow checking in "int". Only in "long" and "long long". Yes, that's what my test case showed. So, whatever implementation would be done, I think it is a good time to introduce some test cases. P.S. I have briefly checked and didn't find a single test case for scanf(). Maybe I looked to the wrong module(s), but test_printf.c might be more or less a good choice. -- With Best Regards, Andy Shevchenko