Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp5160586pjo; Tue, 11 Feb 2020 05:06:56 -0800 (PST) X-Google-Smtp-Source: APXvYqyJ6YrQYgWC9Lkoxq034MPhdkRNYg+Vul8rB/rM6+0yyUyfKXfYw/sJtufh9gEUgwj9lofm X-Received: by 2002:a9d:831:: with SMTP id 46mr5252397oty.295.1581426416487; Tue, 11 Feb 2020 05:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581426416; cv=none; d=google.com; s=arc-20160816; b=lqjEt0uVjYNPDZ+9C26rbLSU4nx1056iHyGcE7AvuOMIuNjQKimF7fWgW1sITimOtt Z0GO/BSl+pmnwTk/G6fDiSrHKKJqmse6W/OuEvTS08acbY/iNrWTpU1B8ADUocmZ7FcV 46ed3h9L5hZUlOV/OMzHutrJKvuPG3cacUFPzZl4E9j3lEFMHXcI9DRB1qqoCzO9D55f rpt9EWmzCTuA38fBz8B572DN2axSHgSa1oh3DFjPS8QhTZMzA3YXKUQsy7G99T2XlwVf dtPsfqgnJLYrsYuqwy+tEp4XF3JznH1Amr0FJ96DjTTYYW4cwElqvLMle3ejzhHfFJ48 XFJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=h0eLTXJODSG9urk7jbCwFOgzg3FrXVlRcd0IvdpMbfo=; b=klVLzQ3YMSe+akEuzC5dMC0JgASkopfRc/vYBoe4CRmrGaux9A/srxa+hEabiQYcDb 6iZZLJRgkswgVcZaG8ZeTRXpFiy/ranjZ8pen87dajvTmSJRpCxUGObgBOYkkiJU9IuT P1qKKfiOdUJnY1EJoFaE0jqal+cPIKJCzas6qIH3QrKDUp/gzwcLSkGW93tBJp9lAZFL Lq1eXGJuP1y3srt0GWuuUBKi4Wg9Zbky3Pt0xYknLDY3X9N5VEbjLcR/jFdI6MfBKO6d dYEKVWX846m5ubZLJre/j7LmLA+CcwSTXt21Hh2+2NZMzz6AVousKXP3Trs8zGZL4kJR 8l0Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si1706331oih.206.2020.02.11.05.06.37; Tue, 11 Feb 2020 05:06:56 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729004AbgBKNFJ (ORCPT + 99 others); Tue, 11 Feb 2020 08:05:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:33656 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728666AbgBKNFI (ORCPT ); Tue, 11 Feb 2020 08:05:08 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3BCF5AD2D; Tue, 11 Feb 2020 13:05:06 +0000 (UTC) Date: Tue, 11 Feb 2020 14:05:05 +0100 From: Petr Mladek To: Sergey Senozhatsky Cc: Nathan Chancellor , Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] printk: Convert a use of sprintf to snprintf in console_unlock Message-ID: <20200211130505.2lj2fm6nslbwgmg6@pathway.suse.cz> References: <20200130221644.2273-1-natechancellor@gmail.com> <20200131070237.GB240941@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200131070237.GB240941@google.com> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2020-01-31 16:02:37, Sergey Senozhatsky wrote: > On (20/01/30 15:16), Nathan Chancellor wrote: > > When CONFIG_PRINTK is disabled (e.g. when building allnoconfig), clang > > warns: > > > > ../kernel/printk/printk.c:2416:10: warning: 'sprintf' will always > > overflow; destination buffer has size 0, but format string expands to at > > least 33 [-Wfortify-source] > > len = sprintf(text, > > ^ > > 1 warning generated. > > > > It is not wrong; text has a zero size when CONFIG_PRINTK is disabled > > because LOG_LINE_MAX and PREFIX_MAX are both zero. Change to snprintf so > > that this case is explicitly handled without any risk of overflow. > > We probably can add a note here that for !CONFIG_PRINTK builds > logbuf overflow is very unlikely. Good point. Well, the sprintf() was used for a well defined string: "** %llu printk messages dropped **\n" "" It could overflow only when anyone modified LOG_LINE_MAX to something really small. It was not the case upstream, definitely. > Otherwise, > Reviewed-by: Sergey Senozhatsky The patch has been committed into printk.git, branch for-5.7. I did not add any extra comment to keep it simple. I hope that it is ok. Best Regards, Petr