Re: [PATCH] sim-auth: Avoid using dbus_message_iter_get_element_count

2017-11-27 Thread Denis Kenzior

Hi Slava,

On 11/27/2017 05:06 AM, Slava Monich wrote:

It's the only thing in ofono that requires dbus 1.9.16 or later and it's
not worth it.

And don't leak DBusMessage on format error.
---
  src/sim-auth.c | 22 +-
  1 file changed, 9 insertions(+), 13 deletions(-)



Applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH] sim-auth: Avoid using dbus_message_iter_get_element_count

2017-11-27 Thread Slava Monich
It's the only thing in ofono that requires dbus 1.9.16 or later and it's
not worth it.

And don't leak DBusMessage on format error.
---
 src/sim-auth.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/sim-auth.c b/src/sim-auth.c
index f9f74d4..7b65738 100644
--- a/src/sim-auth.c
+++ b/src/sim-auth.c
@@ -369,9 +369,7 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection 
*conn,
struct ofono_sim_auth *sa = data;
DBusMessageIter iter;
DBusMessageIter array;
-   int i;
uint8_t *aid;
-   int rands;
 
if (sa->pending)
return __ofono_error_busy(msg);
@@ -381,27 +379,22 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection 
*conn,
if (dbus_message_iter_get_arg_type() != DBUS_TYPE_ARRAY)
return __ofono_error_invalid_format(msg);
 
-   rands = dbus_message_iter_get_element_count();
-
-   if (rands > 3 || rands < 2)
-   return __ofono_error_invalid_format(msg);
-
sa->pending = g_new0(struct auth_request, 1);
-   sa->pending->msg = dbus_message_ref(msg);
-   sa->pending->num_rands = rands;
 
dbus_message_iter_recurse(, );
 
-   for (i = 0; i < sa->pending->num_rands; i++) {
+   while (dbus_message_iter_get_arg_type() == DBUS_TYPE_ARRAY) {
int nelement;
DBusMessageIter in;
 
dbus_message_iter_recurse(, );
 
-   if (dbus_message_iter_get_arg_type() != DBUS_TYPE_BYTE)
+   if (dbus_message_iter_get_arg_type() != DBUS_TYPE_BYTE ||
+   sa->pending->num_rands == SIM_AUTH_MAX_RANDS)
goto format_error;
 
-   dbus_message_iter_get_fixed_array(, >pending->rands[i],
+   dbus_message_iter_get_fixed_array(,
+   >pending->rands[sa->pending->num_rands++],
);
 
if (nelement != 16)
@@ -410,12 +403,15 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection 
*conn,
dbus_message_iter_next();
}
 
+   if (sa->pending->num_rands < 2)
+   goto format_error;
+
/*
 * retrieve session from SIM
 */
aid = find_aid_by_path(sa->aid_objects, dbus_message_get_path(msg));
sa->pending->session = __ofono_sim_get_session_by_aid(sa->sim, aid);
-
+   sa->pending->msg = dbus_message_ref(msg);
sa->pending->watch_id = __ofono_sim_add_session_watch(
sa->pending->session, get_session_cb, sa, NULL);
 
-- 
1.9.1

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono