From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756485AbbEFHtn (ORCPT ); Wed, 6 May 2015 03:49:43 -0400 Received: from mail-la0-f53.google.com ([209.85.215.53]:33200 "EHLO mail-la0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756463AbbEFHti (ORCPT ); Wed, 6 May 2015 03:49:38 -0400 From: Rasmus Villemoes To: Alexey Dobriyan Cc: Andrew Morton , Linux Kernel Subject: Re: [PATCH 04/10] sscanf: fix overflow Organization: D03 References: <20150502004714.GA21655@p183.telecom.by> <20150502005116.GD21655@p183.telecom.by> <87egmvfj2c.fsf@rasmusvillemoes.dk> X-Hashcash: 1:20:150506:linux-kernel@vger.kernel.org::UQQBeqmrHoV+5LQ/:0000000000000000000000000000000001Lxt X-Hashcash: 1:20:150506:adobriyan@gmail.com::JiyVHXMgVzDKxo4+:0000000000000000000000000000000000000000001ezP X-Hashcash: 1:20:150506:akpm@linux-foundation.org::BZOTH7z39NwfOMcb:0000000000000000000000000000000000006+yk Date: Wed, 06 May 2015 09:49:35 +0200 In-Reply-To: (Alexey Dobriyan's message of "Tue, 5 May 2015 14:10:36 +0300") Message-ID: <878ud2rvqo.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 05 2015, Alexey Dobriyan wrote: > On Tue, May 5, 2015 at 12:51 PM, Rasmus Villemoes > wrote: >> On Sat, May 02 2015, Alexey Dobriyan wrote: >> >>> Fun fact: >>> >>> uint8_t val; >>> sscanf("256", "%hhu", &val); >>> >>> will return 1 (as it should), and make val=0 (as it should not). >>> >> >> What do you base these "should" and "should not" on? Both C99 and POSIX >> say that the behaviour is undefined - the kernel can obviously define >> its own semantics for scanf, but what do you think they should be? > > POSIX can say whatever it wants, That was sort of the point, POSIX doesn't say anything, which is why I asked what you think the semantics should be. > it's about common sense. > > sscanf(), both kernel and libc, in this situation returns 0 when "0" > character is nowhere to be found in the string! It should either > return 25 Really? Do you consider it common sense that sscanf("256 123", "%hhu%d", &x, &y) can end up returning 2, putting 25 in x and 6 in y? > or do not return anything I agree that _that_ would be the sane thing to do, but again, I'm confused why you then said the first example should return 1. Rasmus