Subject: Re: [bug report] buffer overflow in isdn capi

From: Tilman Schmidt <[email-masked]>
Date: Tue, 03 Jun 2014 00:48:02 +0200

Hello all,

on 01.04.2014 17:48, Dan Carpenter wrote:
> The command_2_index() function is buggy and leads to a buffer
> overflow. Does anyone know how to fix this?

AFAICS this is still unfixed.
As an easy fix I propose:

- --- a/drivers/isdn/capi/capiutil.c
+++ b/drivers/isdn/capi/capiutil.c
@@ -203,14 +203,7 @@ static unsigned char *cpars[] =
 /*-------------------------------------------------------*/
 static unsigned command_2_index(unsigned c, unsigned sc)
 {
- -       if (c & 0x80)
- -               c = 0x9 + (c & 0x0f);
- -       else if (c <= 0x0f);
- -       else if (c == 0x41)
- -               c = 0x9 + 0x1;
- -       else if (c == 0xff)
- -               c = 0x00;
- -       return (sc & 3) * (0x9 + 0x9) + c;
+       return (sc & 3) * (0x9 + 0x9) + ((c & 0xf0) ? 0x9 : 0) + (c &
0x0f);
 }

 /*-------------------------------------------------------*/

This produces identical results to the current function for
all legal values of c (0x00..0x08, 0x41, 0x80..0x88, 0xff)
and guarantees that the result is <= 0x4e for all possible
inputs, whether legal or not. It also makes it clearer what
that function actually does.

Unless somebody points out a serious flaw with this I'll test it
and submit a formal patch.

Karsten's other concern about unhandled NULL pointers in the
mnames[] and cpars[] arrays should be addressed separately IMHO.

Regards,
Tilman

- -- 
Tilman Schmidt                              E-Mail: [email-masked]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)