n_gsm: Fix message length handling when building header
PATCH 1/2 n_gsm: Fix message length handling when building header
From: \"Mills, Ken K\" <[email protected]>
Fix message length handling when building header
When the message length is greater than 127, the length field in the header is built incorrectly. According to the spec, when the length is less than 128 the length field is a single byte formatted as: bbbbbbb1. When it is greater than 127 then the field is two bytes of the format: bbbbbbb0 bbbbbbbb.
Signed-off-by Ken Mills <[email protected]>
Signed-off-by Alan Cox <[email protected]>
---
drivers/tty/n_gsm.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/tty/n_gsm.c +2 -2
@@ -726,8 +726,8 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)if (msg->len <128 ) *--dp = (msg->len <<1 ) |EA ;else { - *--dp = ((msg->len &127 ) <<1 ) |EA ; - *--dp = (msg->len >>6 ) &0xfe ; + *--dp = (msg->len >>7 );/* bits 7 - 15 */ + *--dp = (msg->len &127 ) <<1 ;/* bits 0 - 6 */ } }
PATCH 2/2 n_gsm: gsm_data_alloc buffer allocation could fail and it is not being checked
From: Ken Mills <[email protected]>
gsm_data_alloc buffer allocation could fail and it is not being checked.
Add check for allocated buffer and return if the buffer allocation fails.
Signed-off-by Ken Mills <[email protected]>
Signed-off-by Alan Cox <[email protected]>
---
drivers/tty/n_gsm.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/tty/n_gsm.c +2 -0
@@ -978,6 +978,8 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, u8 *data, {struct gsm_msg *msg; msg =gsm_data_alloc (gsm,0 , dlen +2 , gsm->ftype); +if (msg ==NULL ) +return ; msg->data[0 ] = (cmd &0xFE ) <<1 |EA ;/* Clear C/R */ msg->data[1 ] = (dlen <<1 ) |EA ;memcpy (msg->data +2 , data, dlen);