From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: xujiahao <xujiahao@cmss.chinamobile.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: sidewinder - size the name buffers to their formats
Date: Sat, 7 Nov 2026 22:33:20 -0800 [thread overview]
Message-ID: <avARPWwbjYnmuTeb@google.com> (raw)
In-Reply-To: <20261106033300.3439313-1-xujiahao@cmss.chinamobile.com>
On Fri, Nov 06, 2026 at 11:33:00AM +0800, xujiahao wrote:
> sw_connect() composes the physical path of each port as "%s/input%d"
> from gameport->phys into a 32-byte array. gameport->phys is a 32-byte
> string and the port number is an int, so the worst case is 31 + 6 + 10
> characters plus the terminator and does not fit.
>
> sw_3dp_id() builds " [PnP %d.%02d id %s rev %s]" into the 40-byte
> comment buffer of sw_connect(). The PnP ID is 7 characters, the
> revision string 8, and the %d arguments are a full-range int as far as
> the compiler can tell, so 44 characters plus the terminator do not fit
> either.
>
> Size both buffers to their formats. Truncation is theoretical with the
> values seen today, but a buffer should not be smaller than what it is
> asked to hold. Building with W=1:
>
> drivers/input/joystick/sidewinder.c:538:58: warning: '%s' directive output may be truncated writing up to 8 bytes into a region of size between 5 and 21 [-Wformat-truncation=]
> drivers/input/joystick/sidewinder.c:727:29: warning: '/input' directive output may be truncated writing 6 bytes into a region of size between 1 and 32 [-Wformat-truncation=]
>
> Signed-off-by: xujiahao <xujiahao@cmss.chinamobile.com>
> ---
> drivers/input/joystick/sidewinder.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
> index 7f37d18c8..2bd5cfe5c 100644
> --- a/drivers/input/joystick/sidewinder.c
> +++ b/drivers/input/joystick/sidewinder.c
> @@ -97,7 +97,7 @@ struct sw {
> struct gameport *gameport;
> struct input_dev *dev[4];
> char name[64];
> - char phys[4][32];
> + char phys[4][64];
> int length;
> int type;
> int bits;
> @@ -574,7 +574,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
> unsigned char *buf = NULL; /* [SW_LENGTH] */
> unsigned char *idbuf = NULL; /* [SW_LENGTH] */
> unsigned char m = 1;
> - char comment[40];
> + char comment[48];
This just wastes memory for something that never happens. We are OK even
if data is truncated.
To shut off the warnings I think we can switch to scnprintf().
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-11-08 6:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 3:33 [PATCH] Input: sidewinder - size the name buffers to their formats xujiahao
2026-11-08 6:33 ` Dmitry Torokhov [this message]
2026-11-09 1:05 ` [PATCH v2] Input: sidewinder - use scnprintf() for the port names xujiahao
2026-11-09 1:31 ` sashiko-bot
2026-11-09 10:45 ` kernel test robot
2026-11-09 20:08 ` kernel test robot
2026-11-10 1:48 ` [PATCH v3] " xujiahao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avARPWwbjYnmuTeb@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xujiahao@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.