Re: [MM] [PATCH] sim: validate IMSI value in +CIMI response



On 08/24/2012 05:04 PM, Ben Chan wrote:
> ---
> This patch is a stripped-down version of the previous patch "sim: retry SIM operations during initialization". It does not retry SIM operations but simply validates the IMSI value.
> 
> A follow-up patch is needed to handle retries appropriately under certain error conditions.
> 

I simplified a bit parse_imsi() as the response string must always be
non-null when there is no error set in the GSimpleAsyncResult.

Pushed now.


>  src/mm-sim.c |   37 +++++++++++++++++++++++++++++++++++--
>  1 files changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/src/mm-sim.c b/src/mm-sim.c
> index 9cd31cc..b917361 100644
> --- a/src/mm-sim.c
> +++ b/src/mm-sim.c
> @@ -1066,15 +1066,48 @@ load_sim_identifier (MMSim *self,
>  /* IMSI */
>  
>  static gchar *
> +parse_imsi (const gchar *response,
> +            GError **error)
> +{
> +    const gchar *s;
> +    int len;
> +    gboolean success;
> +
> +    if (response) {
> +        success = TRUE;
> +        for (s = response, len = 0; *s; ++s, ++len) {
> +            /* IMSI is a number with 15 or less decimal digits. */
> +            if (!isdigit (*s) || len > 15) {
> +                success = FALSE;
> +                break;
> +            }
> +        }
> +        if (success)
> +            return g_strdup (response);
> +    }
> +
> +    g_set_error (error,
> +                 MM_CORE_ERROR,
> +                 MM_CORE_ERROR_FAILED,
> +                 "Invalid +CIMI response '%s'", response ? response : "<null>");
> +    return NULL;
> +}
> +
> +static gchar *
>  load_imsi_finish (MMSim *self,
>                    GAsyncResult *res,
>                    GError **error)
>  {
> +    const gchar *result;
>      gchar *imsi;
>  
>      if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
>          return NULL;
> -    imsi = g_strdup (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
> +    result = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
> +
> +    imsi = parse_imsi (result, error);
> +    if (!imsi)
> +        return NULL;
>  
>      mm_dbg ("loaded IMSI: %s", imsi);
>      return imsi;
> @@ -1093,7 +1126,7 @@ load_imsi (MMSim *self,
>          MM_BASE_MODEM (self->priv->modem),
>          "+CIMI",
>          3,
> -        TRUE,
> +        FALSE,
>          (GAsyncReadyCallback)load_imsi_command_ready,
>          g_simple_async_result_new (G_OBJECT (self),
>                                     callback,
> 


-- 
Aleksander


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