Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7953571rwd; Tue, 20 Jun 2023 08:17:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YUWyvDOIvXpE1/X0TSN+HNvn5t8I/mWLt+zrgNNwIW8b6N/ACPHyLeshC4COlx3Dajgas X-Received: by 2002:a17:90a:c292:b0:24e:3452:5115 with SMTP id f18-20020a17090ac29200b0024e34525115mr12128614pjt.37.1687274278242; Tue, 20 Jun 2023 08:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687274278; cv=none; d=google.com; s=arc-20160816; b=aMYVARO/4rkASx1uZlKAbztNWKiRU31kt742wQrHuTzxUxLGp57iOekYvMUbX1FZtp +FsPHhGyxZQQA5ApZIZCbDv3HS7h08oKFGMtHasYK2UeoFIDX4QBiu0JUcUp5aQxcCzh 0NljHP6z4Kz0uSyDyg9+TL9vWP5Ilt8K2oK+pz39mKNDsn8PpykBWT6rjEN7mLcmtKca gxYS6bvaW5HtRg2/JBtXvUYQ0s9UflbQf93qCGFbJ28TTAMqIsDUoqWWCXPADHratoxR Ir6oAM3N31/qwEkh+fIiDh5PP4t10cIa55uG1gnsTVWGEOQmFWVOuo1DNYkcTo4+mV5H 4mfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rqpOqDJxJplxaFADnW3a40r4fQxrfN6aq0JgDGMsckI=; b=YV/dFHLl1kJ5hxJiDuTFzyScYSpaoK60X1ih571JQ84dPyTovi/bnW1lW+0bMyO/lr ORON7ZFKXusGLBTUhX06tdjhDoVTa/wiDQcpcSmFKf9MpQ6a4t4wl0FquHvRh11hWURY QjjZ4GBTw4tEjF/eIzhSNOjcwP/IM1dHyrrCFaccgzmnKrpOwYAcanGEveUu72CaSgBQ 9IoEwvaSFWQ7hjpOyu3/GPy5XCnlnZdrV/LgXf1FJTsW/s9yRxvsuEJyogBaCX3Uw+UY f0ohWHByr0B9kwhWg0LBDMIbUPwAn+WTXY0xp0FHjHusfwdwSwk1rt8QMpskHDIVqby9 OJNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=WsYTKvhv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d10-20020a17090a498a00b00250365255b9si9879049pjh.116.2023.06.20.08.17.45; Tue, 20 Jun 2023 08:17:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=WsYTKvhv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233437AbjFTO6l (ORCPT + 99 others); Tue, 20 Jun 2023 10:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233427AbjFTO61 (ORCPT ); Tue, 20 Jun 2023 10:58:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9094C19A8 for ; Tue, 20 Jun 2023 07:58:03 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 165A82188D; Tue, 20 Jun 2023 14:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1687273082; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rqpOqDJxJplxaFADnW3a40r4fQxrfN6aq0JgDGMsckI=; b=WsYTKvhvZFFpTFvj8EJ/4/anTVBa2ayWDpooa0WfzLc745laU0WIinTsKVENocgsoA8wYZ Py+fk/LPFM0WOliGx3qTTtHhvtU47oR5oA2ngp558q+DdVCHuiXHvowN8Y9HQOJ/PWBJAi JjZFAxcYMm5dp76ZogiesoH9PVpYSBE= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 64C852C141; Tue, 20 Jun 2023 14:58:01 +0000 (UTC) Date: Tue, 20 Jun 2023 16:57:55 +0200 From: Petr Mladek To: Andy Shevchenko Cc: David Laight , 'Demi Marie Obenour' , Alexey Dobriyan , "linux-kernel@vger.kernel.org" , Rasmus Villemoes , Hans de Goede , Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Steven Rostedt , Sergey Senozhatsky Subject: Re: [PATCH v3 0/4] Make sscanf() stricter Message-ID: References: <23df90dd35874fd89c64906e6a6de164@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2023-06-20 16:52:42, Andy Shevchenko wrote: > On Tue, Jun 20, 2023 at 03:34:09PM +0200, Petr Mladek wrote: > > On Thu 2023-06-15 14:23:59, Andy Shevchenko wrote: > > > On Thu, Jun 15, 2023 at 08:06:46AM +0000, David Laight wrote: > > ... > > > + %pj or another %p modifiers would be hard to understand either. > > > > Yes, we have %pe but I think that only few people really use it. > > And it is kind of self-explanatory because it is typically > > used together with ERR_PTR() and with variables called > > "err" or "ret". > > j, besides the luck of no (yet) use in the kernel's printf(), is > described for printf(3) > > j A following integer conversion corresponds to an intmax_t or uintmax_t > argument, or a following n conversion corresponds to a pointer to an > intmax_t argument. I see, I have missed this coincidence. And we would really need to use %pj. %jd requires intmax_t variable. Otherwise, the compiler produces: kernel/lib/test.c:10:17: error: format ‘%jd’ expects argument of type ‘intmax_t *’, but argument 3 has type ‘int *’ [-Werror=format=] sscanf(str, "%jd hello.", &tmp); Hmm, %pj might even make some sense for sscanf() which requires pointers anyway. But still, we would lose the compiler check of the size of the passed buffer. This is actually my concern with many other %p modifiers. The compiler is not able to check that we pass the right pointer. I know that this might happen even with wrong buffer passed to %s or so. But number types is another category. > So, I think among all proposals, this one is the best (while all of them may > sound not good). I still prefer the custom handler when it is not too complex. Or if there are many users, we could create sscanf_strict() or so. Best Regards, Petr