diff options
author | Karol Lewandowski <k.lewandowsk@samsung.com> | 2022-07-13 00:19:52 +0200 |
---|---|---|
committer | Karol Lewandowski <k.lewandowsk@samsung.com> | 2022-07-13 15:11:59 +0200 |
commit | 8979158110e7c490dad3ecff25aa3e291786d08d (patch) | |
tree | 7325b49bc5d410dca157ba98422970c7fa4cd193 | |
parent | c7eb5d5338610cf9686fe754de7b9a4a9cb22b46 (diff) | |
download | sessiond-8979158110e7c490dad3ecff25aa3e291786d08d.tar.gz sessiond-8979158110e7c490dad3ecff25aa3e291786d08d.tar.bz2 sessiond-8979158110e7c490dad3ecff25aa3e291786d08d.zip |
lib: get_current_user: Avoid off-by-one while copying user name
- fix off-by-one error while copying user name
- tizen style fixes
Change-Id: If2fc3204413f748526959f567fad9b032502cd75
-rw-r--r-- | libsessiond/src/lib.c | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/libsessiond/src/lib.c b/libsessiond/src/lib.c index 381dd34..4ca4c5d 100644 --- a/libsessiond/src/lib.c +++ b/libsessiond/src/lib.c @@ -1146,46 +1146,39 @@ EXPORT_API int subsession_get_user_list(int session_uid, subsession_user_t **use EXPORT_API int subsession_get_current_user(int session_uid, subsession_user_t user) { - return_if(session_uid_is_not_valid(session_uid, - current_user_ptr_is_null(user))) + return_if(session_uid_is_not_valid(session_uid, current_user_ptr_is_null(user))) MAKE_SURE_CONNECTION_IS_NOT_NULL(); - GVariant * params = g_variant_new("(i)", session_uid); - if(params == NULL) { + GVariant *params = g_variant_new("(i)", session_uid); + if (params == NULL) { return_with_log_error_result_(SUBSESSION_ERROR_OUT_OF_MEMORY) } - GVariant *retgv = NULL; GError *call_sync_error = NULL; - - retgv = g_dbus_connection_call_sync( - conn_config_, - dbus_method_call.GetCurrentUser, params, - NULL, - G_DBUS_CALL_FLAGS_NONE, - libsessiond_default_timeout, - NULL, - &call_sync_error - ); + g_autoptr(GVariant) retgv = g_dbus_connection_call_sync(conn_config_, + dbus_method_call.GetCurrentUser, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + libsessiond_default_timeout, + NULL, + &call_sync_error); if (!retgv || call_sync_error) { LOGE("Dbus error: %s for method: %s", g_dbus_error_get_remote_error(call_sync_error), dbus_method_call.GetCurrentUser); int ret = map_dbus_call_error_to_return_value(call_sync_error); - log_if_error_(ret); g_error_free(call_sync_error); + log_if_error_(ret); return ret; } - char *get_user = NULL; + g_autofree char *get_user = NULL; maybe_g_variant_get_or_error_invalid(retgv,"(s)", &get_user); - - if(get_user == NULL) { + if (get_user == NULL) { return_with_log_error_result_(SUBSESSION_ERROR_OUT_OF_MEMORY); } - - memcpy(user, get_user, strnlen(get_user, SUBSESSION_USER_MAXLEN)+1); - free(get_user); + memcpy(user, get_user, strnlen(get_user, sizeof(subsession_user_t)-1) + 1); return SUBSESSION_ERROR_NONE; } |