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

RE: [bluetooth-dev] bug in set_local_hostname in bt_if.c



> -----Original Message-----
> From: Matthias Fuchs [mailto:matthias.fuchs@xxxxxxx.com]
> Sent: 12 June 2002 14:22
> To: Bluetooth-dev
> Subject: [bluetooth-dev] bug in set_local_hostname in bt_if.c
> 
> Hi,
> 
> the function set_local_hostname contains a little bug that can result
> in a never returning function:
> 
> The while() loop can be endless, when the local_name only 
> contains invalid characters
> (outside ' ' and 'z'). In such cases len and local_name are 
> never increased and the break
> condition for the loop is never reached.

Actually it will fail as soon as it finds an incorrect character
as the local_name pointer will never be increased then...

> Further *local_name++ increases *local_name and not the 
> local_name pointer.

As you already noted this is incorrect. ;)

>      while (*local_name && len < LOCAL_NAME_LENGTH)
>      {
>        if (*local_name >= ' ' && *local_name <= 'z')
>        {
>          buf[len++] = *local_name++;
>        }
>      }
> 
> I think the code should look like this:
> 
>      while (*local_name && len < LOCAL_NAME_LENGTH)
>      {
>        if (*local_name >= ' ' && *local_name <= 'z')

This if-statement should rather be:

         if (*local_name == ' ' || isgraph(*local_name))
>        {
>          buf[len++] = *local_name;
>        }
>        local_name++;	
>      }

//Peter
-
To unsubscribe from this list: send the line "unsubscribe bluetooth-dev" in
the body of a message to majordomo@xxxxxxx.com