Skip to contentSkip to conversation

simauth: fixup adding more dbus return checks

PATCH Applied James Prestwood 3 participants 3 messages Oct 16, 2017 – Oct 23, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 simauth: fixup adding more dbus return checks

---
 src/sim-auth.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
src/sim-auth.c +17 -6
index b9552b5..9ae5574 100644
@@ -427,6 +427,7 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
 	DBusMessageIter array;
 	int i;
 	struct sim_app_record *app;
+	int rands;
 
 	if (sim->pending)
 		return __ofono_error_busy(msg);
@@ -436,11 +437,16 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
 		return __ofono_error_invalid_format(msg);
 
+	rands = dbus_message_iter_get_element_count(&iter);
+
+	if (rands > 3 || rands < 2)
+		return __ofono_error_invalid_format(msg);
+
 	sim->pending = malloc(sizeof(struct auth_request));
 	sim->pending->msg = dbus_message_ref(msg);
 	sim->pending->umts = 0;
 	sim->pending->cb_count = 0;
-	sim->pending->num_rands = dbus_message_iter_get_element_count(&iter);
+	sim->pending->num_rands = rands;
 
 	dbus_message_iter_recurse(&iter, &array);
 
@@ -450,14 +456,14 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
 
 		dbus_message_iter_recurse(&array, &in);
 
+		if (dbus_message_iter_get_arg_type(&in) != DBUS_TYPE_BYTE)
+			goto format_error;
+
 		dbus_message_iter_get_fixed_array(&in, &sim->pending->rands[i],
 				&nelement);
 
-		if (nelement != 16) {
-			g_free(sim->pending);
-			sim->pending = NULL;
-			return __ofono_error_invalid_format(msg);
-		}
+		if (nelement != 16)
+			goto format_error;
 
 		dbus_message_iter_next(&array);
 	}
@@ -467,6 +473,11 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
 	sim->driver->open_channel(sim, app->aid, open_channel_cb, sim);
 
 	return NULL;
+
+format_error:
+	g_free(sim->pending);
+	sim->pending = NULL;
+	return __ofono_error_invalid_format(msg);
 }
 
 static DBusMessage *umts_common(DBusConnection *conn, DBusMessage *msg,
Signature · 1 line
2.7.4
#1 lore raw

Hi James,

Quoted 4 lines · James Prestwood
---
  src/sim-auth.c | 23 +++++++++++++++++------
  1 file changed, 17 insertions(+), 6 deletions(-)

Applied, thanks.

Regards,
-Denis

#2 lore raw
In reply to James Prestwood

Hi James,

Quoted 17 lines · James Prestwood
---
  src/sim-auth.c | 23 +++++++++++++++++------
  1 file changed, 17 insertions(+), 6 deletions(-)
src/sim-auth.c +1 -0
index b9552b5..9ae5574 100644
@@ -427,6 +427,7 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
  	DBusMessageIter array;
  	int i;
  	struct sim_app_record *app;
+	int rands;
 
  	if (sim->pending)
  		return __ofono_error_busy(msg);

src/sim-auth.c static DBusMessage *usim_gsm_authenticate(DBusConnection *conn, · line 440

Quoted 4 lines
src/sim-auth.c +1 -0
@@ -436,11 +437,16 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
  	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
  		return __ofono_error_invalid_format(msg);
 
+	rands = dbus_message_iter_get_element_count(&iter);

It appears that dbus_message_iter_get_element_count() requires dbus 1.9.16 or later, would it be possible to avoid it?

Thanks,
-Slava