You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
6.8 KiB
163 lines
6.8 KiB
2 months ago
|
From 6de3d5c2481b219271ee747739995266d5f76ba0 Mon Sep 17 00:00:00 2001
|
||
|
From: Lubomir Rintel <lkundrak@v3.sk>
|
||
|
Date: Thu, 23 May 2024 10:06:47 +0200
|
||
|
Subject: [PATCH 3/9] qmicli: avoid leaking the input messages
|
||
|
|
||
|
In various places in we follow this pattern:
|
||
|
|
||
|
input = qmi_message_uim_power_on_sim_input_new ();
|
||
|
if (bad arguments) {
|
||
|
complain();
|
||
|
return; // leak input
|
||
|
}
|
||
|
issue_message(input);
|
||
|
|
||
|
Let's, instead, always do the argument sanity checks before allocating
|
||
|
the message, to avoid leaking the message.
|
||
|
---
|
||
|
src/qmicli/qmicli-uim.c | 8 ++++----
|
||
|
src/qmicli/qmicli-wds.c | 31 +++++++++++++++++++++----------
|
||
|
2 files changed, 25 insertions(+), 14 deletions(-)
|
||
|
|
||
|
diff --git a/src/qmicli/qmicli-uim.c b/src/qmicli/qmicli-uim.c
|
||
|
index e344a682..2238c55b 100644
|
||
|
--- a/src/qmicli/qmicli-uim.c
|
||
|
+++ b/src/qmicli/qmicli-uim.c
|
||
|
@@ -849,13 +849,13 @@ power_on_sim_input_create (const gchar *slot_str)
|
||
|
guint slot;
|
||
|
GError *error = NULL;
|
||
|
|
||
|
- input = qmi_message_uim_power_on_sim_input_new ();
|
||
|
-
|
||
|
if (!qmicli_read_uint_from_string (slot_str, &slot) || (slot > G_MAXUINT8)) {
|
||
|
g_printerr ("error: invalid slot number\n");
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
+ input = qmi_message_uim_power_on_sim_input_new ();
|
||
|
+
|
||
|
if (!qmi_message_uim_power_on_sim_input_set_slot (input, slot, &error)) {
|
||
|
g_printerr ("error: could not create SIM power on input: %s\n", error->message);
|
||
|
g_error_free (error);
|
||
|
@@ -907,13 +907,13 @@ power_off_sim_input_create (const gchar *slot_str)
|
||
|
guint slot;
|
||
|
GError *error = NULL;
|
||
|
|
||
|
- input = qmi_message_uim_power_off_sim_input_new ();
|
||
|
-
|
||
|
if (!qmicli_read_uint_from_string (slot_str, &slot) || (slot > G_MAXUINT8)) {
|
||
|
g_printerr ("error: invalid slot number\n");
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
+ input = qmi_message_uim_power_off_sim_input_new ();
|
||
|
+
|
||
|
if (!qmi_message_uim_power_off_sim_input_set_slot (input, slot, &error)) {
|
||
|
g_printerr ("error: could not create SIM power off input: %s\n", error->message);
|
||
|
g_error_free (error);
|
||
|
diff --git a/src/qmicli/qmicli-wds.c b/src/qmicli/qmicli-wds.c
|
||
|
index 66a9d7cd..0bae3b40 100644
|
||
|
--- a/src/qmicli/qmicli-wds.c
|
||
|
+++ b/src/qmicli/qmicli-wds.c
|
||
|
@@ -3197,14 +3197,14 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
#if defined HAVE_QMI_MESSAGE_WDS_SET_IP_FAMILY
|
||
|
if (set_ip_family_str) {
|
||
|
QmiMessageWdsSetIpFamilyInput *input;
|
||
|
+ QmiWdsIpFamily preference;
|
||
|
|
||
|
- input = qmi_message_wds_set_ip_family_input_new ();
|
||
|
switch (atoi (set_ip_family_str)) {
|
||
|
case 4:
|
||
|
- qmi_message_wds_set_ip_family_input_set_preference (input, QMI_WDS_IP_FAMILY_IPV4, NULL);
|
||
|
+ preference = QMI_WDS_IP_FAMILY_IPV4;
|
||
|
break;
|
||
|
case 6:
|
||
|
- qmi_message_wds_set_ip_family_input_set_preference (input, QMI_WDS_IP_FAMILY_IPV6, NULL);
|
||
|
+ preference = QMI_WDS_IP_FAMILY_IPV6;
|
||
|
break;
|
||
|
default:
|
||
|
g_printerr ("error: unknown IP type '%s' (not 4 or 6)\n",
|
||
|
@@ -3212,6 +3212,10 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
operation_shutdown (FALSE);
|
||
|
return;
|
||
|
}
|
||
|
+
|
||
|
+ input = qmi_message_wds_set_ip_family_input_new ();
|
||
|
+ qmi_message_wds_set_ip_family_input_set_preference (input, preference, NULL);
|
||
|
+
|
||
|
g_debug ("Asynchronously set IP family...");
|
||
|
qmi_client_wds_set_ip_family (client,
|
||
|
input,
|
||
|
@@ -3441,7 +3445,6 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
guint profile_index;
|
||
|
|
||
|
split = g_strsplit (delete_profile_str, ",", -1);
|
||
|
- input = qmi_message_wds_delete_profile_input_new ();
|
||
|
|
||
|
if (g_strv_length (split) != 2) {
|
||
|
g_printerr ("error: expected 2 arguments for delete profile command\n");
|
||
|
@@ -3471,6 +3474,8 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
+ input = qmi_message_wds_delete_profile_input_new ();
|
||
|
+
|
||
|
qmi_message_wds_delete_profile_input_set_profile_identifier (input, profile_type, (guint8)profile_index, NULL);
|
||
|
|
||
|
g_strfreev (split);
|
||
|
@@ -3490,12 +3495,12 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
#if defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_LIST && defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_SETTINGS
|
||
|
if (get_profile_list_str) {
|
||
|
QmiMessageWdsGetProfileListInput *input;
|
||
|
+ QmiWdsProfileType profile_type;
|
||
|
|
||
|
- input = qmi_message_wds_get_profile_list_input_new ();
|
||
|
if (g_str_equal (get_profile_list_str, "3gpp"))
|
||
|
- qmi_message_wds_get_profile_list_input_set_profile_type (input, QMI_WDS_PROFILE_TYPE_3GPP, NULL);
|
||
|
+ profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
|
||
|
else if (g_str_equal (get_profile_list_str, "3gpp2"))
|
||
|
- qmi_message_wds_get_profile_list_input_set_profile_type (input, QMI_WDS_PROFILE_TYPE_3GPP2, NULL);
|
||
|
+ profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
|
||
|
else {
|
||
|
g_printerr ("error: invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'\n",
|
||
|
get_profile_list_str);
|
||
|
@@ -3503,6 +3508,9 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
+ input = qmi_message_wds_get_profile_list_input_new ();
|
||
|
+ qmi_message_wds_get_profile_list_input_set_profile_type (input, profile_type, NULL);
|
||
|
+
|
||
|
g_debug ("Asynchronously get profile list...");
|
||
|
qmi_client_wds_get_profile_list (ctx->client,
|
||
|
input,
|
||
|
@@ -3574,12 +3582,12 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
#if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_SETTINGS
|
||
|
if (get_default_settings_str) {
|
||
|
QmiMessageWdsGetDefaultSettingsInput *input;
|
||
|
+ QmiWdsProfileType profile_type;
|
||
|
|
||
|
- input = qmi_message_wds_get_default_settings_input_new ();
|
||
|
if (g_str_equal (get_default_settings_str, "3gpp"))
|
||
|
- qmi_message_wds_get_default_settings_input_set_profile_type (input, QMI_WDS_PROFILE_TYPE_3GPP, NULL);
|
||
|
+ profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
|
||
|
else if (g_str_equal (get_default_settings_str, "3gpp2"))
|
||
|
- qmi_message_wds_get_default_settings_input_set_profile_type (input, QMI_WDS_PROFILE_TYPE_3GPP2, NULL);
|
||
|
+ profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
|
||
|
else {
|
||
|
g_printerr ("error: invalid default type '%s'. Expected '3gpp' or '3gpp2'.'\n",
|
||
|
get_default_settings_str);
|
||
|
@@ -3587,6 +3595,9 @@ qmicli_wds_run (QmiDevice *device,
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
+ input = qmi_message_wds_get_default_settings_input_new ();
|
||
|
+ qmi_message_wds_get_default_settings_input_set_profile_type (input, profile_type, NULL);
|
||
|
+
|
||
|
g_debug ("Asynchronously get default settings...");
|
||
|
qmi_client_wds_get_default_settings (ctx->client,
|
||
|
input,
|
||
|
--
|
||
|
2.45.2
|
||
|
|