Commit aa0b3796 authored by Lubomir Rintel's avatar Lubomir Rintel 🥕
Browse files

modem-broadband: ignore late callbacks

If libmm invokes callbacks after the connect context has been disposed
we should just ignore them. Fixes crash on dereferencing already freed
connect context (due to explicit disconnection while the modem is
connecting):

  NetworkManager[29074]: <info>  [1462383917.8718] (ttyACM1): modem state changed, 'disconnecting' --> 'registered' (reason: user-requested)
  NetworkManager[29074]: <info>  [1462383917.8719] (ttyACM1): modem state changed, 'registered' --> 'connecting' (reason: user-requested)
  NetworkManager[29074]: <info>  [1462383917.8720] device (ttyACM1): state change: deactivating -> disconnected (reason 'connection-removed') [110 30 38]
  NetworkManager[29074]: <info>  [1462383917.8758] (ttyACM1): modem state changed, 'connecting' --> 'disconnecting' (reason: user-requested)
  NetworkManager[29074]: <warn>  [1462383917.8909] (ttyACM1): failed to connect modem: Dial operation has been cancelled

  (NetworkManager:29074): NetworkManager-wwan-CRITICAL **: modem_prepare_result: assertion 'state == NM_DEVICE_STATE_PREPARE' failed
  NetworkManager[29074]: <info>  [1462383917.8912] (ttyACM1): modem state changed, 'disconnecting' --> 'registered' (reason: user-requested)
  NetworkManager[29074]: <info>  [1462383917.8913] (ttyACM1): modem state changed, 'registered' --> 'connecting' (reason: user-requested)
  NetworkManager[29074]: <info>  [1462383917.9693] (ttyACM1): modem state changed, 'connecting' --> 'registered' (reason: user-requested)

  Program received signal SIGSEGV, Segmentation fault.
  connect_ready (simple_iface=<optimized out>, res=0x7fffe0009200, self=0x555555a8d670 [NMModemBroadband]) at nm-modem-broadband.c:329
  329                     if (!ctx->first_error) {
  (gdb) bt
  #0  0x00007fffea01272a in connect_ready (simple_iface=<optimized out>, res=0x7fffe0009200, self=0x555555a8d670 [NMModemBroadband]) at nm-modem-broadband.c:329
  #1  0x00007ffff546a297 in g_simple_async_result_complete (simple=0x7fffe0009200 [GSimpleAsyncResult]) at gsimpleasyncresult.c:801
  #2  0x00007fffe9d82fec in connect_context_complete_and_free (ctx=ctx@entry=0x7fffdc00c550) at mm-modem-simple.c:93
  #3  0x00007fffe9d83155 in simple_connect_ready (self=0x7fffdc00c960 [MMModemSimple], res=0x555555a7c2b0, ctx=0x7fffdc00c550) at mm-modem-simple.c:159
  #4  0x00007ffff547af93 in g_task_return_now (task=0x555555a7c2b0 [GTask]) at gtask.c:1106
  #5  0x00007ffff547b62e in g_task_return (task=0x555555a7c2b0 [GTask], type=<optimized out>) at gtask.c:1164
  #6  0x00007ffff54d4239 in reply_cb (connection=<optimized out>, res=<optimized out>, user_data=0x555555a7c2b0) at gdbusproxy.c:2570
  #7  0x00007ffff547af93 in g_task_return_now (task=0x7fffdc004470 [GTask]) at gtask.c:1106
  #8  0x00007ffff547b62e in g_task_return (task=0x7fffdc004470 [GTask], type=<optimized out>) at gtask.c:1164
  #9  0x00007ffff54c8c9f in g_dbus_connection_call_done (source=<optimized out>, result=0x7fffe00036f0, user_data=0x7fffdc004470) at gdbusconnection.c:5702
  #10 0x00007ffff547af93 in g_task_return_now (task=0x7fffe00036f0 [GTask]) at gtask.c:1106
  #11 0x00007ffff547afc9 in complete_in_idle_cb (task=0x7fffe00036f0) at gtask.c:1120
  #12 0x00007ffff4eb7d7a in g_main_context_dispatch (context=0x555555a4a000) at gmain.c:3152
  #13 0x00007ffff4eb7d7a in g_main_context_dispatch (context=context@entry=0x555555a4a000) at gmain.c:3767
  #14 0x00007ffff4eb80b8 in g_main_context_iterate (context=0x555555a4a000, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3838
  #15 0x00007ffff4eb838a in g_main_loop_run (loop=0x555555a48780) at gmain.c:4032
  #16 0x00005555555aebf2 in main (argc=1, argv=0x7fffffffdc78) at main.c:477
  (gdb)
parent d5c19220
......@@ -310,6 +310,10 @@ connect_ready (MMModemSimple *simple_iface,
NMModemIPMethod ip6_method = NM_MODEM_IP_METHOD_UNKNOWN;
self->priv->bearer = mm_modem_simple_connect_finish (simple_iface, res, &error);
if (!ctx)
return;
if (!self->priv->bearer) {
if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PIN) ||
(g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED) &&
......@@ -377,9 +381,14 @@ connect_ready (MMModemSimple *simple_iface,
static void
send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self)
{
GError *error = NULL;
GError *error = NULL;
if (!mm_sim_send_pin_finish (sim, result, &error)) {
mm_sim_send_pin_finish (sim, result, &error);
if (!self->priv->ctx || self->priv->ctx->step != CONNECT_STEP_UNLOCK)
return;
if (error) {
if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PIN) ||
(g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED) &&
mm_modem_get_unlock_required (self->priv->modem_iface) == MM_MODEM_LOCK_SIM_PIN)) {
......@@ -389,7 +398,7 @@ send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self)
}
g_error_free (error);
return;
}
}
self->priv->ctx->step++;
connect_context_step (self);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment