Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp429642ybi; Sat, 15 Jun 2019 04:09:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqytdytTzT9y7rNfP3Q/o7wBMIFrOevnJfRvFnvLer/xfX026WYoikhdWO7pnjvq3/q7ZALU X-Received: by 2002:a17:90a:a00d:: with SMTP id q13mr15643932pjp.80.1560596945810; Sat, 15 Jun 2019 04:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560596945; cv=none; d=google.com; s=arc-20160816; b=j2tqDb5kgN+lkQvCryKtybEd2bR4tMeTVN1c6gXLhszja8LbDZqzQ4G6ED5dEOvcae q8dnxmV8ZfWMgDVQ7Y4TD0n97svcdKHj0yfIot3mdnsYMiVLeSXDj/a9I0tDnBb63869 ac5cdsqEjbYL9efm94zehn06ZOdwlC4xvg+BEyrj7ILW8CX5UZYnzBTrQ/OW5AFbxX6O inj+cs8RnDKCpH4g9kpBH8H88DsWpH66BkvWDGsz0gk8jtD5s//X17ziLTWTMcnUWRGo 3QWYJZS3IAJvqF9am6snQEWYNLHNxRrZYMVYVknUgU94DIp1lZI3arxx89rAYfz2BS1r bFOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=5TURGXD4Y2R84S/sctOaDZ1q6Gc1L2qZv2x24+gH580=; b=FJqqbY7g9OdCcyuVHCE8q9SJGn/anbo+h21CZoLcyXGjIarNYBM63s4aZSKee4896d dk1IMBrpfZM3d1bJjLX3xMZXq4IviJjE93iW+D/yW5ftH8py93FRGi0rv0F/tjoWysGH FdLOf78o6WYyc5n5Bv4ikcQjGXc2M/O7zqNuRo5MWryedmlQd1st5vHWoPFOkqQ1sD38 4iw7MCL5cyF5JcfpyTWQKyu0mPRIiwch/f/NScRHoTq4mWYskIYyxzQVZ9MpXrGeBJfD BVG5itp38Oow5BwLTDIzu/OCiZyYhpl2NlxL812+6l8dqcF+ZR8IE9joWerP5/mvEUaw TzkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a18iU4uM; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si4510643pju.84.2019.06.15.04.08.48; Sat, 15 Jun 2019 04:09:05 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=a18iU4uM; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726523AbfFOLIp (ORCPT + 99 others); Sat, 15 Jun 2019 07:08:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:43090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbfFOLIp (ORCPT ); Sat, 15 Jun 2019 07:08:45 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE52320868; Sat, 15 Jun 2019 11:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560596924; bh=d4PhO/BCiNtOO+NzHnU8fQBmsAsfyWLsC7FyggSF/sU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=a18iU4uMjhWaK3rrpKek54hoED5rbc5LDwQPRdlQmFImUT7bN2sOWdHBAjj/qcuHc 4gvGCLO9K4IY8ZOzTOkqBCAjzpRaudk74oQhbsMSYVkKzHxsdLGuGC4ICR+Xqlj544 g4KapH6rPLCwVzwjZpYXJy4s9a9OGyE89VbTFR2g= Message-ID: Subject: Re: [PATCH 1/3] lib/vsprintf: add snprintf_noterm From: Jeff Layton To: Joe Perches , "Yan, Zheng" Cc: Linux Kernel Mailing List , ceph-devel , Andrew Morton , Ilya Dryomov , Zheng Yan , Sage Weil , agruenba@redhat.com Date: Sat, 15 Jun 2019 07:08:41 -0400 In-Reply-To: <75c8f066c3aa2e20db2e1554a4d28c20b2952724.camel@perches.com> References: <20190614134625.6870-1-jlayton@kernel.org> <20190614134625.6870-2-jlayton@kernel.org> <75c8f066c3aa2e20db2e1554a4d28c20b2952724.camel@perches.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.2 (3.32.2-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-06-14 at 19:58 -0700, Joe Perches wrote: > On Sat, 2019-06-15 at 10:41 +0800, Yan, Zheng wrote: > > On Fri, Jun 14, 2019 at 9:48 PM Jeff Layton wrote: > > > The getxattr interface returns a length after filling out the value > > > buffer, and the convention with xattrs is to not NULL terminate string > > > data. > > > > > > CephFS implements some virtual xattrs by using snprintf to fill the > > > buffer, but that always NULL terminates the string. If userland sends > > > down a buffer that is just the right length to hold the text without > > > termination then we end up truncating the value. > > > > > > Factor the formatting piece of vsnprintf into a separate helper > > > function, and have vsnprintf call that and then do the NULL termination > > > afterward. Then add a snprintf_noterm function that calls the new helper > > > to populate the string but skips the termination. > > Is this function really necessary enough to add > the additional stack use to the generic case? > The only alternative I saw was to allocate an extra buffer in the callers, call snprintf to populate that and then copy the result into the destination buffer sans termination. I really would like to avoid that here. Does breaking this code out into a helper add any significant stack usage? I didn't see it that way, but I am quite concerned about not slowing down the generic vsnprintf routine. > Why not add have this function call vsnprintf > and then terminate the string separately? > I don't quite follow what you're suggesting here. vsnprintf is what does the termination today, and we need a function that doesn't do that. -- Jeff Layton