mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Input: sidewinder - size the name buffers to their formats
@ 2026-11-06  3:33 xujiahao
  2026-11-08  6:33 ` Dmitry Torokhov
  2026-11-09  1:05 ` [PATCH v2] Input: sidewinder - use scnprintf() for the port names xujiahao
  0 siblings, 2 replies; 4+ messages in thread
From: xujiahao @ 2026-11-06  3:33 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, xujiahao

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];
 
 	comment[0] = 0;
 
-- 
2.43.0




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-09 10:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06  3:33 [PATCH] Input: sidewinder - size the name buffers to their formats xujiahao
2026-11-08  6:33 ` Dmitry Torokhov
2026-11-09  1:05 ` [PATCH v2] Input: sidewinder - use scnprintf() for the port names xujiahao
2026-11-09 10:45   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®