From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbcCIGth (ORCPT ); Wed, 9 Mar 2016 01:49:37 -0500 Received: from mail-yw0-f178.google.com ([209.85.161.178]:35090 "EHLO mail-yw0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751101AbcCIGt2 (ORCPT ); Wed, 9 Mar 2016 01:49:28 -0500 MIME-Version: 1.0 In-Reply-To: <1457469654-17059-3-git-send-email-linux@rasmusvillemoes.dk> References: <1457469654-17059-1-git-send-email-linux@rasmusvillemoes.dk> <1457469654-17059-3-git-send-email-linux@rasmusvillemoes.dk> Date: Wed, 9 Mar 2016 08:49:27 +0200 Message-ID: Subject: Re: [RFC 2/7] Input: joystick - avoid fragile snprintf use From: Andy Shevchenko To: Rasmus Villemoes Cc: Kees Cook , Andrew Morton , Dmitry Torokhov , linux-input , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 8, 2016 at 10:40 PM, Rasmus Villemoes wrote: > Passing overlapping src and dst buffers to snprintf is fragile, and > while it currently works for the special case of passing dst as the > argument corresponding to an initial "%s" in the format string, any > other use would very likely lead to chaos. It's easy enough to avoid, > so let's do that. > static void analog_name(struct analog *analog) > { > - snprintf(analog->name, sizeof(analog->name), "Analog %d-axis %d-button", > + int ret = 0; Assignment is not needed. > + > + ret = scnprintf(analog->name, sizeof(analog->name), "Analog %d-axis %d-button", -- With Best Regards, Andy Shevchenko