diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-08-14 15:36:44 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-09-12 17:14:36 +0000 |
commit | 6e84f3d45934e4f1e334c4bfd0d9a43d88889039 (patch) | |
tree | 31acc1e5dec441b3cda6fd35a4739bf5a942dff6 /src/mm-shared-qmi.c | |
parent | 47ed19d5be68f139d4fbb00c997cd2805488ace7 (diff) |
iface-modem-location: validate SUPL server address
Devices will expect SUPL server given as either IP:PORT or FQDN:PORT,
so just avoid saying we require a 'URL' because it's not true.
We will use a new helper method to parse and validate user-provided
SUPL server address.
Diffstat (limited to 'src/mm-shared-qmi.c')
-rw-r--r-- | src/mm-shared-qmi.c | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index dd08d7fd..5c91aefe 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -113,36 +113,6 @@ set_supl_server_context_free (SetSuplServerContext *ctx) g_slice_free (SetSuplServerContext, ctx); } -static gboolean -parse_as_ip_port (const gchar *supl, - guint32 *out_ip, - guint32 *out_port) -{ - gboolean valid = FALSE; - gchar **split; - guint port; - guint32 ip; - - split = g_strsplit (supl, ":", -1); - if (g_strv_length (split) != 2) - goto out; - - if (!mm_get_uint_from_str (split[1], &port)) - goto out; - if (port == 0 || port > G_MAXUINT16) - goto out; - if (inet_pton (AF_INET, split[0], &ip) <= 0) - goto out; - - *out_ip = ip; - *out_port = port; - valid = TRUE; - -out: - g_strfreev (split); - return valid; -} - static GArray * parse_as_utf16_url (const gchar *supl) { @@ -197,7 +167,7 @@ pds_set_supl_server (GTask *task) SetSuplServerContext *ctx; QmiMessagePdsSetAgpsConfigInput *input; guint32 ip; - guint32 port; + guint16 port; GArray *url; self = g_task_get_source_object (task); @@ -211,7 +181,7 @@ pds_set_supl_server (GTask *task) else if (mm_iface_modem_is_cdma (MM_IFACE_MODEM (self))) qmi_message_pds_set_agps_config_input_set_network_mode (input, QMI_PDS_NETWORK_MODE_CDMA, NULL); - if (parse_as_ip_port (ctx->supl, &ip, &port)) + if (mm_parse_supl_address (ctx->supl, NULL, &ip, &port, NULL)) qmi_message_pds_set_agps_config_input_set_location_server_address (input, ip, port, NULL); else { url = parse_as_utf16_url (ctx->supl); @@ -312,7 +282,7 @@ loc_set_supl_server (GTask *task) SetSuplServerContext *ctx; QmiMessageLocSetServerInput *input; guint32 ip; - guint32 port; + guint16 port; self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); @@ -325,8 +295,8 @@ loc_set_supl_server (GTask *task) else if (mm_iface_modem_is_cdma (MM_IFACE_MODEM (self))) qmi_message_loc_set_server_input_set_server_type (input, QMI_LOC_SERVER_TYPE_CDMA_PDE, NULL); - if (parse_as_ip_port (ctx->supl, &ip, &port)) - qmi_message_loc_set_server_input_set_ipv4 (input, ip, port, NULL); + if (mm_parse_supl_address (ctx->supl, NULL, &ip, &port, NULL)) + qmi_message_loc_set_server_input_set_ipv4 (input, ip, (guint32) port, NULL); else qmi_message_loc_set_server_input_set_url (input, ctx->supl, NULL); |