RE: [PATCH] ST_CORE: Error triggered by convert "char" to "int"

From: Liu, Chuansheng
Date: Thu Jan 10 2013 - 03:45:01 EST




> -----Original Message-----
> From: Bi, Chao
> Sent: Thursday, January 10, 2013 4:27 PM
> To: alan@xxxxxxxxxxxxxxx; gregkh@xxxxxxxxxxxxxxxxxxx;
> akpm@xxxxxxxxxxxxxxxxxxxx; pavan_savoy@xxxxxx
> Cc: Liu, Chuansheng; linux-kernel@xxxxxxxxxxxxxxx
> Subject: [PATCH] ST_CORE: Error triggered by convert "char" to "int"
>
>
> When st driver decodes protocol index received from raw data,
> it does a value convert from "char" to "int". Because it's sign
> extension from bit8 to bit32, the "int" value maybe minus, in
> another word, the protocol index might be minus, but driver doesn't
> filter such case and may continue access memory pointed by this
> minus index.
>
> This patch is to change the variable type of index from "int"
> to "unsigned char", so that it avoids do such kind of type
> conversion.
>
Some infos:
when the type is minus, it will cause panic, because the below code
just consider type >= ST_MAX_CHANNELS case, no type < 0 case,
but it really happened.
if ((type >= ST_MAX_CHANNELS) ||
(st_gdata->list[type] == NULL)) {

Changing type from int to unsigned char can get benefit from the above
code.
If possible:
Acked-by: liu chuansheng <chuansheng.liu@xxxxxxxxx>

Thanks.
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i