aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/sidewinder.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor_core@ameritech.net>2006-06-26 01:45:48 -0400
committerDmitry Torokhov <dtor_core@ameritech.net>2006-06-26 01:45:48 -0400
commit10ca4c0a622a942e55dc8a6d57ebd441089c9e38 (patch)
treedcdb84833a46e80ff95fb73b0d1f83b737f3d2b9 /drivers/input/joystick/sidewinder.c
parent08ffce4560e0133e10634b0dd85eecee11257a1c (diff)
Input: fix potential overflows in driver/input/joystick
Change all sprintfs into snprintfs to make sure we won't stomp on data adjacent to our buffers. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/joystick/sidewinder.c')
-rw-r--r--drivers/input/joystick/sidewinder.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 95c0de7964a0..e58b22c018e4 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -541,7 +541,7 @@ static void sw_print_packet(char *name, int length, unsigned char *buf, char bit
541 * Unfortunately I don't know how to do this for the other SW types. 541 * Unfortunately I don't know how to do this for the other SW types.
542 */ 542 */
543 543
544static void sw_3dp_id(unsigned char *buf, char *comment) 544static void sw_3dp_id(unsigned char *buf, char *comment, size_t size)
545{ 545{
546 int i; 546 int i;
547 char pnp[8], rev[9]; 547 char pnp[8], rev[9];
@@ -554,7 +554,7 @@ static void sw_3dp_id(unsigned char *buf, char *comment)
554 554
555 pnp[7] = rev[8] = 0; 555 pnp[7] = rev[8] = 0;
556 556
557 sprintf(comment, " [PnP %d.%02d id %s rev %s]", 557 snprintf(comment, size, " [PnP %d.%02d id %s rev %s]",
558 (int) ((sw_get_bits(buf, 8, 6, 1) << 6) | /* Two 6-bit values */ 558 (int) ((sw_get_bits(buf, 8, 6, 1) << 6) | /* Two 6-bit values */
559 sw_get_bits(buf, 16, 6, 1)) / 100, 559 sw_get_bits(buf, 16, 6, 1)) / 100,
560 (int) ((sw_get_bits(buf, 8, 6, 1) << 6) | 560 (int) ((sw_get_bits(buf, 8, 6, 1) << 6) |
@@ -695,7 +695,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
695 sw->type = SW_ID_FFP; 695 sw->type = SW_ID_FFP;
696 sprintf(comment, " [AC %s]", sw_get_bits(idbuf,38,1,3) ? "off" : "on"); 696 sprintf(comment, " [AC %s]", sw_get_bits(idbuf,38,1,3) ? "off" : "on");
697 } else 697 } else
698 sw->type = SW_ID_PP; 698 sw->type = SW_ID_PP;
699 break; 699 break;
700 case 66: 700 case 66:
701 sw->bits = 3; 701 sw->bits = 3;
@@ -703,7 +703,8 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
703 sw->length = 22; 703 sw->length = 22;
704 case 64: 704 case 64:
705 sw->type = SW_ID_3DP; 705 sw->type = SW_ID_3DP;
706 if (j == 160) sw_3dp_id(idbuf, comment); 706 if (j == 160)
707 sw_3dp_id(idbuf, comment, sizeof(comment));
707 break; 708 break;
708 } 709 }
709 } 710 }
@@ -733,8 +734,10 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
733 for (i = 0; i < sw->number; i++) { 734 for (i = 0; i < sw->number; i++) {
734 int bits, code; 735 int bits, code;
735 736
736 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); 737 snprintf(sw->name, sizeof(sw->name),
737 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); 738 "Microsoft SideWinder %s", sw_name[sw->type]);
739 snprintf(sw->phys[i], sizeof(sw->phys[i]),
740 "%s/input%d", gameport->phys, i);
738 741
739 sw->dev[i] = input_dev = input_allocate_device(); 742 sw->dev[i] = input_dev = input_allocate_device();
740 if (!input_dev) { 743 if (!input_dev) {