Re: [BlueZ 01/12] gatt-server: Don't allocate negative data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2024-07-04 at 15:25 +0300, Pauli Virtanen wrote:
> Hi,
> 
> to, 2024-07-04 kello 12:24 +0200, Bastien Nocera kirjoitti:
> > Set a lower-bound to the data MTU to avoid allocating -1 elements
> > if
> > bt_att_get_mtu() returns zero.
> > 
> > Error: OVERRUN (CWE-119): [#def36] [important]
> > bluez-5.76/src/shared/gatt-server.c:1121:2: zero_return: Function
> > call "bt_att_get_mtu(server->att)" returns 0.
> > bluez-5.76/src/shared/gatt-server.c:1121:2: assignment: Assigning:
> > "data->mtu" = "bt_att_get_mtu(server->att)". The value of "data-
> > >mtu" is now 0.
> > bluez-5.76/src/shared/gatt-server.c:1123:19: assignment: Assigning:
> > "__n" = "(size_t)(data->mtu - 1UL)". The value of "__n" is now
> > 18446744073709551615.
> > bluez-5.76/src/shared/gatt-server.c:1123:19: assignment: Assigning:
> > "__s" = "1UL".
> > bluez-5.76/src/shared/gatt-server.c:1123:19: overrun-buffer-arg:
> > Calling "memset" with "__p" and "__n * __s" is suspicious because
> > of the very large index, 18446744073709551615. The index may be due
> > to a negative parameter being interpreted as unsigned. [Note: The
> > source code implementation of the function has been overridden by a
> > builtin model.]
> > 1121|		data->mtu = bt_att_get_mtu(server->att);
> > 1122|		data->length = 0;
> > 1123|->		data->rsp_data = new0(uint8_t, data->mtu - 1);
> > 1124|
> > 1125|		return data;
> > ---
> >  src/shared/gatt-server.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c
> > index 3a53d5dfde6b..c587553d655d 100644
> > --- a/src/shared/gatt-server.c
> > +++ b/src/shared/gatt-server.c
> > @@ -1118,7 +1118,7 @@ static struct read_mult_data
> > *read_mult_data_new(struct bt_gatt_server *server,
> >  	data->server = server;
> >  	data->num_handles = num_handles;
> >  	data->cur_handle = 0;
> > -	data->mtu = bt_att_get_mtu(server->att);
> > +	data->mtu = MAX(bt_att_get_mtu(server->att),
> > BT_ATT_DEFAULT_LE_MTU);
> 
> Is this correct, probably MTU less than default are valid?

This is the same code as in bt_gatt_server_new().

> 
> >  	data->length = 0;
> >  	data->rsp_data = new0(uint8_t, data->mtu - 1);
> >  
> 
> Might be better to instead: MAX(data->mtu, 1) - 1

I'd be fine with either, if somebody knows that particular part of the
code better than I do...





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux