Added bounds safety checking
This commit is contained in:
@@ -49,6 +49,7 @@ static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now);
|
|||||||
*
|
*
|
||||||
* @return Returns 1 if handshake was successful, 0 if not.
|
* @return Returns 1 if handshake was successful, 0 if not.
|
||||||
*/
|
*/
|
||||||
|
#define HANDSHAKE_BYTES_USED 12
|
||||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) {
|
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
|
|||||||
cc->r_shoulder = 0;
|
cc->r_shoulder = 0;
|
||||||
cc->l_shoulder = 0;
|
cc->l_shoulder = 0;
|
||||||
|
|
||||||
if (data[0] == 0xFF) {
|
if (data[0] == 0xFF || len < HANDSHAKE_BYTES_USED) {
|
||||||
/*
|
/*
|
||||||
* Sometimes the data returned here is not correct.
|
* Sometimes the data returned here is not correct.
|
||||||
* This might happen because the wiimote is lagging
|
* This might happen because the wiimote is lagging
|
||||||
@@ -69,7 +70,7 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
|
|||||||
* but since the next 16 bytes are the same, just use
|
* but since the next 16 bytes are the same, just use
|
||||||
* those.
|
* those.
|
||||||
*/
|
*/
|
||||||
if (data[16] == 0xFF) {
|
if (len < 17 || len < HANDSHAKE_BYTES_USED + 16 || data[16] == 0xFF) {
|
||||||
/* get the calibration data */
|
/* get the calibration data */
|
||||||
byte* handshake_buf = (byte *)malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
byte* handshake_buf = (byte *)malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
*
|
*
|
||||||
* @return Returns 1 if handshake was successful, 0 if not.
|
* @return Returns 1 if handshake was successful, 0 if not.
|
||||||
*/
|
*/
|
||||||
|
+#define HANDSHAKE_BYTES_USED 14
|
||||||
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) {
|
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -60,8 +61,7 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
|
|||||||
nc->accel_calib.st_alpha = wm->accel_calib.st_alpha;
|
nc->accel_calib.st_alpha = wm->accel_calib.st_alpha;
|
||||||
|
|
||||||
/* decrypt data */
|
/* decrypt data */
|
||||||
|
if (data[0] == 0xFF || len < HANDSHAKE_BYTES_USED) {
|
||||||
if (data[0] == 0xFF) {
|
|
||||||
/*
|
/*
|
||||||
* Sometimes the data returned here is not correct.
|
* Sometimes the data returned here is not correct.
|
||||||
* This might happen because the wiimote is lagging
|
* This might happen because the wiimote is lagging
|
||||||
@@ -72,7 +72,7 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
|
|||||||
* but since the next 16 bytes are the same, just use
|
* but since the next 16 bytes are the same, just use
|
||||||
* those.
|
* those.
|
||||||
*/
|
*/
|
||||||
if (data[16] == 0xFF) {
|
if (len < 17 || len < HANDSHAKE_BYTES_USED + 16 || data[16] == 0xFF) {
|
||||||
/* get the calibration data */
|
/* get the calibration data */
|
||||||
byte* handshake_buf = (byte *)malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
byte* handshake_buf = (byte *)malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user