[PATCH] qmicli,wds: fix uninitialized values in --wds-start-network
Dan Williams
dcbw at redhat.com
Tue Mar 21 18:07:54 UTC 2017
On Tue, 2017-03-21 at 13:34 +0100, Aleksander Morgado wrote:
> The 'ip-type' support in --wds-start-network was introduced in commit
> 81c21379, and that patch lacked a proper initialization of the
> 'ip_type' field (e.g. as QMI_WDS_IP_FAMILY_UNSPECIFIED) inside the
> 'props' struct.
>
> A follow up commit, 4c678418, tried to fix that by assuming the
> 'ip_type' field was initialized to 0 instead of
> QMI_WDS_IP_FAMILY_UNSPECIFIED, which wasn't the case either, as the
> 'props' struct isn't static and therefore requires explicit
> initialization of its members.
Can't we do:
StartNetworkProperties props = { 0 };
...
props.auth = QMI_WDS_AUTHENTICATION_NONE;
props.ip_type = QMI_WDS_IP_FAMILY_UNSPECIFIED;
IIRC that'll zero it out at the compiler level and we don't need the
memset.
Dan
> This patch tries to address the issue by using memset() to initialize
> to 0/FALSE/NULL the whole struct members, and then explicitly
> initialize to valid enum values the enum members.
>
> This also fixes the initialization of the 'autoconnect' and
> 'autoconnect_set' fields, which were not initialized to anything.
> ---
>
> Hey Dan,
>
> I believe the fix done in 4c678418 (assuming the struct member was
> initialized to 0) wasn't the proper one; instead we should have
> explicitly initialized the struct member to
> QMI_WDS_IP_FAMILY_UNSPECIFIED.
>
> How about this fix to initialize the whole struct to 0/NULL/FALSE and
> then the enum members to specific enum values?
>
> ---
> src/qmicli/qmicli-wds.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/src/qmicli/qmicli-wds.c b/src/qmicli/qmicli-wds.c
> index 75d7992..55d10b7 100644
> --- a/src/qmicli/qmicli-wds.c
> +++ b/src/qmicli/qmicli-wds.c
> @@ -473,15 +473,13 @@ start_network_input_create (const gchar *str)
> gchar *ip_type_str = NULL;
> gchar **split = NULL;
> QmiMessageWdsStartNetworkInput *input = NULL;
> - StartNetworkProperties props = {
> - .apn = NULL,
> - .profile_index_3gpp = 0,
> - .profile_index_3gpp2 = 0,
> - .auth = QMI_WDS_AUTHENTICATION_NONE,
> - .auth_set = FALSE,
> - .username = NULL,
> - .password = NULL,
> - };
> + StartNetworkProperties props;
> +
> + /* Initialize all struct members to 0/FALSE/NULL, and explicitly
> initialize
> + * the enum members to actual enum values */
> + memset (&props, 0, sizeof (props));
> + props.auth = QMI_WDS_AUTHENTICATION_NONE;
> + props.ip_type = QMI_WDS_IP_FAMILY_UNSPECIFIED;
>
> /* An empty string is totally valid (i.e. no TLVs) */
> if (!str[0])
> @@ -537,7 +535,7 @@ start_network_input_create (const gchar *str)
> qmi_message_wds_start_network_input_set_profile_index_3gpp2
> (input, props.profile_index_3gpp2, NULL);
>
> /* Set IP Type */
> - if (props.ip_type != 0) {
> + if (props.ip_type != QMI_WDS_IP_FAMILY_UNSPECIFIED) {
> qmi_message_wds_start_network_input_set_ip_family_preference
> (input, props.ip_type, NULL);
> if (props.ip_type == QMI_WDS_IP_FAMILY_IPV4)
> ip_type_str = "4";
> --
> 2.12.0
More information about the libqmi-devel
mailing list