Re: [PATCH 3/8] vpn: Avoid using uninitialized prefix_len

Denis Kenzior <[email protected]> Mon, 14 Apr 2025 10:37:45 -0500
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
Hi Jussi,

On 4/10/25 10:58 AM, Jussi Laakkonen wrote:
> Clang complains about the prefix_len being possibly uninitialized. Set
> the max for IPv6 prefix len as the value.
> ---
>   plugins/vpn.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/plugins/vpn.c b/plugins/vpn.c
> index 42396d2a..9664c82f 100644
> --- a/plugins/vpn.c
> +++ b/plugins/vpn.c
> @@ -4,6 +4,7 @@
>    *
>    *  Copyright (C) 2012-2013  Intel Corporation. All rights reserved.
>    *  Copyright (C) 2019-2021  Jolla Ltd. All rights reserved.
> + *  Copyright (C) 2025  Jolla Mobile Ltd
>    *
>    *  This program is free software; you can redistribute it and/or modify
>    *  it under the terms of the GNU General Public License version 2 as
> @@ -388,7 +389,7 @@ static int extract_ip(DBusMessageIter *array, int family,
>   {
>   	DBusMessageIter dict;
>   	char *address = NULL, *gateway = NULL, *netmask = NULL, *peer = NULL;
> -	unsigned char prefix_len;
> +	unsigned char prefix_len = 128;

How does this help?  You may want to share the actual error verbatim. 
'prefix_len' is set from 'atoi(netmask)'.

The use of atoi seems to be pretty dangerous here though.

> 
>   	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
>   		return -EINVAL;
> --
> 2.39.5
> 
> 

Regards,
-Denis