netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 2/3] i4l: silence compiler warnings for array access in Eicon DIVA ISDN driver
@ 2010-03-11 22:07 akpm
  2010-03-15 22:48 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: akpm @ 2010-03-11 22:07 UTC (permalink / raw)
  To: isdn; +Cc: netdev, akpm, imunsie, mac, sgayda2

From: Ian Munsie <imunsie@au.ibm.com>

When compiling this driver, the compiler throws the following warnings:

drivers/isdn/hardware/eicon/message.c:8426: warning: array subscript is above array bounds
drivers/isdn/hardware/eicon/message.c:8427: warning: array subscript is above array bounds
drivers/isdn/hardware/eicon/message.c:8434: warning: array subscript is above array bounds
drivers/isdn/hardware/eicon/message.c:8435: warning: array subscript is above array bounds
drivers/isdn/hardware/eicon/message.c:8436: warning: array subscript is above array bounds
drivers/isdn/hardware/eicon/message.c:8447: warning: array subscript is above array bounds

This arises from the particular semantics the driver is using to write to
the nlc array (static byte[256]).  The array has a length in byte 0
followed by a T30_INFO struct starting at byte 1.

The T30_INFO struct has a number of variable length strings after the
station_id entry, which cannot be explicitly defined in the struct and the
driver accesses them with an array index to station_id beyond the length
of station_id.

This patch merely changes the semantics that the driver uses to access the
entries after the station_id entry to use the original 256 byte nlc array
taking the offset and length of the station_id entry to calculate where to
write in the array, thereby silencing the warning.

Signed-off-by: Ian Munsie <imunsie@au.ibm.com>
Cc: Armin Schindler <mac@melware.de>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Stoyan Gaydarov <sgayda2@uiuc.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/isdn/hardware/eicon/message.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff -puN drivers/isdn/hardware/eicon/message.c~i4l-silence-compiler-warnings-for-array-access-in-eicon-diva-isdn-driver drivers/isdn/hardware/eicon/message.c
--- a/drivers/isdn/hardware/eicon/message.c~i4l-silence-compiler-warnings-for-array-access-in-eicon-diva-isdn-driver
+++ a/drivers/isdn/hardware/eicon/message.c
@@ -8423,17 +8423,17 @@ static word add_b23(PLCI *plci, API_PARS
             pos = 0;
           else
           {
-            ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
-            ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
+            nlc[1 + offsetof(T30_INFO, station_id) + 20 + pos++] = ' ';
+            nlc[1 + offsetof(T30_INFO, station_id) + 20 + pos++] = ' ';
             len = (byte)b3_config_parms[2].length;
             if (len > 20)
               len = 20;
             if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
             {
               for (i = 0; i < len; i++)
-                ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte   *)b3_config_parms[2].info)[1+i];
-              ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
-              ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
+                nlc[1 + offsetof(T30_INFO, station_id) + 20 + pos++] = ((byte   *)b3_config_parms[2].info)[1+i];
+              nlc[1 + offsetof(T30_INFO, station_id) + 20 + pos++] = ' ';
+              nlc[1 + offsetof(T30_INFO, station_id) + 20 + pos++] = ' ';
             }
           }
         }
@@ -8444,9 +8444,8 @@ static word add_b23(PLCI *plci, API_PARS
         ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
         nlc[0] += (byte)(pos + len);
         for (i = 0; i < len; i++)
-          ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte   *)b3_config_parms[3].info)[1+i];
-        }
-      else
+          nlc[1 + offsetof(T30_INFO, station_id) + 20 + pos++] =  ((byte   *)b3_config_parms[3].info)[1+i];
+      } else
         ((T30_INFO *)&nlc[1])->head_line_len = 0;
 
       plci->nsf_control_bits = 0;
_

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

* Re: [patch 2/3] i4l: silence compiler warnings for array access in Eicon DIVA ISDN driver
  2010-03-11 22:07 [patch 2/3] i4l: silence compiler warnings for array access in Eicon DIVA ISDN driver akpm
@ 2010-03-15 22:48 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2010-03-15 22:48 UTC (permalink / raw)
  To: akpm; +Cc: isdn, netdev, imunsie, mac, sgayda2

From: akpm@linux-foundation.org
Date: Thu, 11 Mar 2010 14:07:24 -0800

> From: Ian Munsie <imunsie@au.ibm.com>
> 
> When compiling this driver, the compiler throws the following warnings:
> 
> drivers/isdn/hardware/eicon/message.c:8426: warning: array subscript is above array bounds
> drivers/isdn/hardware/eicon/message.c:8427: warning: array subscript is above array bounds
> drivers/isdn/hardware/eicon/message.c:8434: warning: array subscript is above array bounds
> drivers/isdn/hardware/eicon/message.c:8435: warning: array subscript is above array bounds
> drivers/isdn/hardware/eicon/message.c:8436: warning: array subscript is above array bounds
> drivers/isdn/hardware/eicon/message.c:8447: warning: array subscript is above array bounds
> 
> This arises from the particular semantics the driver is using to write to
> the nlc array (static byte[256]).  The array has a length in byte 0
> followed by a T30_INFO struct starting at byte 1.
> 
> The T30_INFO struct has a number of variable length strings after the
> station_id entry, which cannot be explicitly defined in the struct and the
> driver accesses them with an array index to station_id beyond the length
> of station_id.
> 
> This patch merely changes the semantics that the driver uses to access the
> entries after the station_id entry to use the original 256 byte nlc array
> taking the offset and length of the station_id entry to calculate where to
> write in the array, thereby silencing the warning.
> 
> Signed-off-by: Ian Munsie <imunsie@au.ibm.com>
> Cc: Armin Schindler <mac@melware.de>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Stoyan Gaydarov <sgayda2@uiuc.edu>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Applied.

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

end of thread, other threads:[~2010-03-15 22:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-11 22:07 [patch 2/3] i4l: silence compiler warnings for array access in Eicon DIVA ISDN driver akpm
2010-03-15 22:48 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).