From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755021AbbIIT0o (ORCPT ); Wed, 9 Sep 2015 15:26:44 -0400 Received: from smtprelay0219.hostedemail.com ([216.40.44.219]:51737 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754956AbbIIT0m (ORCPT ); Wed, 9 Sep 2015 15:26:42 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:800:960:967:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2525:2553:2560:2563:2682:2685:2828:2859:2914:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6119:6261:7903:8603:9025:10004:10400:10848:11026:11232:11233:11473:11658:11914:12043:12296:12438:12517:12519:12555:12663:12740:13069:13311:13357:14096:14097:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: aunt13_74799878c203c X-Filterd-Recvd-Size: 2676 Message-ID: <1441826799.17219.80.camel@perches.com> Subject: Re: [PATCH] lib/vsprintf.c: increase the size of the field_width variable From: Joe Perches To: Rasmus Villemoes Cc: Maurizio Lombardi , akpm@linux-foundation.org, tj@kernel.org, linux-kernel@vger.kernel.org Date: Wed, 09 Sep 2015 12:26:39 -0700 In-Reply-To: <87mvwv4ea2.fsf@rasmusvillemoes.dk> References: <1441793590-23856-1-git-send-email-mlombard@redhat.com> <1441816432.17219.57.camel@perches.com> <87mvwv4ea2.fsf@rasmusvillemoes.dk> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2015-09-09 at 20:51 +0200, Rasmus Villemoes wrote: > On Wed, Sep 09 2015, Joe Perches wrote: > > this makes the sizeof struct printf_spec more than > > 8 bytes which isn't desireable on x86-32. > > I'm pretty sure struct printf_spec > purposely has sizeof==8 to allow it to be (relatively cheaply) passed > around by value. True. https://lkml.org/lkml/2010/3/6/141 > > %*pb is meant for smallish bitmaps, not big ones. > > Yup. And that leads to my other confusion: Given that the expected > output is given as "0-15", does the bitmap really consist of > S16_MAX > bits with only the first 16 set? No idea. Tejun? Perhaps the code in lib/vsprintf.c that sets spec.field_width and spec.precision from format argument input should be changed to use a temporary int and clamped to S16_MIN -> S16_MAX. Something like: --- lib/vsprintf.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 7f0cdd2..2782129 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1913,13 +1913,21 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) break; } - case FORMAT_TYPE_WIDTH: - spec.field_width = va_arg(args, int); + case FORMAT_TYPE_WIDTH: { + int tmp = va_arg(args, int); + + spec.field_width = (s16)clamp_t(int, tmp, + S16_MIN, S16_MAX); break; + } - case FORMAT_TYPE_PRECISION: - spec.precision = va_arg(args, int); + case FORMAT_TYPE_PRECISION: { + int tmp = va_arg(args, int); + + spec.precision = (s16)clamp_t(int, tmp, + S16_MIN, S16_MAX); break; + } case FORMAT_TYPE_CHAR: { char c;