From cda7a100f38eb93e2ff1b93a1505ae33bb0c0cac Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 23 Mar 2018 11:03:52 -0400 Subject: [PATCH] jsauthority: stop using JS_GetStringCharsZ it's not around anymore. Signed-off-by: Ray Strode https://bugs.freedesktop.org/show_bug.cgi?id=105865 --- src/polkitbackend/polkitbackendjsauthority.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index 80bf06e..686de3f 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -1063,228 +1063,225 @@ call_js_function_with_runaway_killer (PolkitBackendJsAuthority *authority, JS::RootedObject js_polkit(authority->priv->cx, authority->priv->js_polkit->get ()); runaway_killer_setup (authority); ret = JS_CallFunctionName(authority->priv->cx, js_polkit, function_name, args, rval); runaway_killer_teardown (authority); return ret; } /* ---------------------------------------------------------------------------------------------------- */ static GList * polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveAuthority *_authority, PolkitSubject *caller, PolkitSubject *subject, PolkitIdentity *user_for_subject, gboolean subject_is_local, gboolean subject_is_active, const gchar *action_id, PolkitDetails *details) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (_authority); GList *ret = NULL; JS::AutoValueArray<2> args(authority->priv->cx); JS::RootedValue rval(authority->priv->cx); guint n; GError *error = NULL; - JSString *ret_jsstr; + JS::RootedString ret_jsstr (authority->priv->cx); gchar *ret_str = NULL; gchar **ret_strs = NULL; JS_BeginRequest (authority->priv->cx); if (!action_and_details_to_jsval (authority, action_id, details, args[0], &error)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error converting action and details to JS object: %s", error->message); g_clear_error (&error); goto out; } if (!subject_to_jsval (authority, subject, user_for_subject, subject_is_local, subject_is_active, args[1], &error)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error converting subject to JS object: %s", error->message); g_clear_error (&error); goto out; } if (!call_js_function_with_runaway_killer (authority, "_runAdminRules", args, &rval)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error evaluating admin rules"); goto out; } if (!rval.isString()) { g_warning ("Expected a string"); goto out; } ret_jsstr = rval.toString(); - ret_str = g_utf16_to_utf8 (JS_GetStringCharsZ (authority->priv->cx, ret_jsstr), -1, NULL, NULL, NULL); + ret_str = JS_EncodeStringToUTF8 (authority->priv->cx, ret_jsstr); if (ret_str == NULL) { - g_warning ("Error converting resulting string to UTF-8: %s", error->message); + g_warning ("Error converting resulting string to UTF-8"); goto out; } ret_strs = g_strsplit (ret_str, ",", -1); for (n = 0; ret_strs != NULL && ret_strs[n] != NULL; n++) { const gchar *identity_str = ret_strs[n]; PolkitIdentity *identity; error = NULL; identity = polkit_identity_from_string (identity_str, &error); if (identity == NULL) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Identity `%s' is not valid, ignoring", identity_str); } else { ret = g_list_prepend (ret, identity); } } ret = g_list_reverse (ret); out: g_strfreev (ret_strs); g_free (ret_str); /* fallback to root password auth */ if (ret == NULL) ret = g_list_prepend (ret, polkit_unix_user_new (0)); JS_MaybeGC (authority->priv->cx); JS_EndRequest (authority->priv->cx); return ret; } /* ---------------------------------------------------------------------------------------------------- */ static PolkitImplicitAuthorization polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAuthority *_authority, PolkitSubject *caller, PolkitSubject *subject, PolkitIdentity *user_for_subject, gboolean subject_is_local, gboolean subject_is_active, const gchar *action_id, PolkitDetails *details, PolkitImplicitAuthorization implicit) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (_authority); PolkitImplicitAuthorization ret = implicit; JS::AutoValueArray<2> args(authority->priv->cx); JS::RootedValue rval(authority->priv->cx); GError *error = NULL; - JSString *ret_jsstr; - const jschar *ret_utf16; + JS::RootedString ret_jsstr (authority->priv->cx); gchar *ret_str = NULL; gboolean good = FALSE; JS_BeginRequest (authority->priv->cx); if (!action_and_details_to_jsval (authority, action_id, details, args[0], &error)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error converting action and details to JS object: %s", error->message); g_clear_error (&error); goto out; } if (!subject_to_jsval (authority, subject, user_for_subject, subject_is_local, subject_is_active, args[1], &error)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error converting subject to JS object: %s", error->message); g_clear_error (&error); goto out; } if (!call_js_function_with_runaway_killer (authority, "_runRules", args, &rval)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error evaluating authorization rules"); goto out; } if (rval.isNull()) { /* this fine, means there was no match, use implicit authorizations */ good = TRUE; goto out; } if (!rval.isString()) { g_warning ("Expected a string"); goto out; } ret_jsstr = rval.toString(); - ret_utf16 = JS_GetStringCharsZ (authority->priv->cx, ret_jsstr); - ret_str = g_utf16_to_utf8 (ret_utf16, -1, NULL, NULL, &error); + ret_str = JS_EncodeStringToUTF8 (authority->priv->cx, ret_jsstr); if (ret_str == NULL) { - g_warning ("Error converting resulting string to UTF-8: %s", error->message); - g_clear_error (&error); + g_warning ("Error converting resulting string to UTF-8"); goto out; } g_strstrip (ret_str); if (!polkit_implicit_authorization_from_string (ret_str, &ret)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Returned result `%s' is not valid", ret_str); goto out; } good = TRUE; out: if (!good) ret = POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED; g_free (ret_str); JS_MaybeGC (authority->priv->cx); JS_EndRequest (authority->priv->cx); return ret; } /* ---------------------------------------------------------------------------------------------------- */ static bool js_polkit_log (JSContext *cx, -- 2.16.2