From patchwork Tue Apr 2 14:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13614266 Received: from mout.web.de (mout.web.de [217.72.192.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BFC081AB6 for ; Tue, 2 Apr 2024 14:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.72.192.78 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712069792; cv=none; b=o2l2teoIbqIZ/VMCOdpCler6+++NGhVpbaT4KZdloMlHNPShnU7Rujmi/Pei9tgaAhCNBk6Iln8J+JOxigIlftSmfQW9+5O076inO37c+Be0YnOlt9dMaHhTXxctAYsPpXis8ml/t/918Rah6iVqvgyKBRJxEstiS9cW66XBefw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712069792; c=relaxed/simple; bh=FiL3QM0HZ4UZ251jS+gr/5JRzUHvwv91iY9Wd5MACXM=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=VXwH4RM1NfXJ2aCe9TI+m96qBnO1Dw4MBvpLatcTVUPp9ie+XcnrVGH36HnmdgIlIKtAZghOMM5OmSTtEkEUqRFaMwGE0vidushhX/69cNIg4I7LbWuiFTV7X+Qhdp8zRqgMD5Kc71zPKNZuVIOhessUtKK3A2C07hznVruXx6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=LAufnEWg; arc=none smtp.client-ip=217.72.192.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="LAufnEWg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1712069788; x=1712674588; i=l.s.r@web.de; bh=oXAI8veZHTAhGJMwDwXvKjRTaWRolhlunxonZ8sWRhU=; h=X-UI-Sender-Class:Date:From:Subject:To:Cc; b=LAufnEWgceO7wnm34LXyS+0FcFkKBNqgs8ccvMW7ge4bAzfrk0lh8UlJzcwbwqsV G4LuiMMlRzqaCQf+s9mM7397hjtVNkmBXilpsgg4qvhujJETk4rf4jvEJFNQI8hrj 9x5oy8f16s+arul6KWsvmXVgecANuErq891iZR7mLMSihGp4T1lP/csmoVyu25VGk b3MrUunDAknqfcNH1StUeQgsiiFgmUAblFHVKjK3VzV49VfZROSnAjMTrNCze8zF2 TuvGMVM8NT/eN5waW9OISIB379+I7AV/LrecnuSe4TWGMyU5bxLflc/DxYKG8K0oH lPvJX1O3HXWkbHrcRQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.19.211]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M1rTG-1rpSYE1YIi-002XJ3; Tue, 02 Apr 2024 16:51:06 +0200 Message-ID: Date: Tue, 2 Apr 2024 16:51:05 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH] imap-send: use xsnprintf to format command Content-Language: en-US To: Git List Cc: Jeff King X-Provags-ID: V03:K1:IQMdw3Z7i3ZrG3X+r7e5XnmwR65mOvItsD7qQ8JXyzGaMUtbctA OqG8WcWLuR5xVnRkwe6ms0wYe77lucRQJ8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intf() wraps vsnprintf(3) and reports attempts to use too small a buffer using BUG(), just like xsnprintf(). It has an extra check that makes sure the buffer size (converted to int) is positive. vsnprintf(3) is supposed to handle a buffer size of zero or bigger than INT_MAX just fine, so this extra comparison doesn't make us any safer. If a platform has a broken implementation, we'd need to work around it in our compat code. Call xsnprintf() instead to reduce code duplication and make the caller slightly more readable by using this more common helper. Signed-off-by: René Scharfe --- Uploaded this message using the patched command, but that's all the testing I did. imap-send.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) -- 2.44.0 diff --git a/imap-send.c b/imap-send.c index f2e1947e63..4caa8668e6 100644 --- a/imap-send.c +++ b/imap-send.c @@ -68,9 +68,6 @@ static void imap_warn(const char *, ...); static char *next_arg(char **); -__attribute__((format (printf, 3, 4))) -static int nfsnprintf(char *buf, int blen, const char *fmt, ...); - static int nfvasprintf(char **strp, const char *fmt, va_list ap) { int len; @@ -500,19 +497,6 @@ static char *next_arg(char **s) return ret; } -__attribute__((format (printf, 3, 4))) -static int nfsnprintf(char *buf, int blen, const char *fmt, ...) -{ - int ret; - va_list va; - - va_start(va, fmt); - if (blen <= 0 || (unsigned)(ret = vsnprintf(buf, blen, fmt, va)) >= (unsigned)blen) - BUG("buffer too small. Please report a bug."); - va_end(va); - return ret; -} - static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx, struct imap_cmd_cb *cb, const char *fmt, va_list ap) @@ -535,11 +519,11 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx, get_cmd_result(ctx, NULL); if (!cmd->cb.data) - bufl = nfsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd); + bufl = xsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd); else - bufl = nfsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n", - cmd->tag, cmd->cmd, cmd->cb.dlen, - CAP(LITERALPLUS) ? "+" : ""); + bufl = xsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n", + cmd->tag, cmd->cmd, cmd->cb.dlen, + CAP(LITERALPLUS) ? "+" : ""); if (0 < verbosity) { if (imap->num_in_progress)