[epiphany/gnome-40] web-app-utils: fix crash when app name contains spaces or hyphens
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-40] web-app-utils: fix crash when app name contains spaces or hyphens
- Date: Thu, 16 Dec 2021 14:27:20 +0000 (UTC)
commit 8f97ce2e15119f8a38ba61946095d63839fce149
Author: Michael Catanzaro <mcatanzaro redhat com>
Date: Thu Dec 16 08:05:21 2021 -0600
web-app-utils: fix crash when app name contains spaces or hyphens
This is a regression from !1032. I incorrectly assumed that web app
names cannot contain hyphens. That's bogus.
lib/ephy-web-app-utils.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index 7ad97d43b..5ea111b42 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -110,8 +110,9 @@ get_app_id_from_gapplication_id (const char *name)
static char *
get_gapplication_id_from_id (const char *id)
{
- g_auto (GStrv) split = NULL;
g_autofree char *gapplication_id = NULL;
+ const char *final_hyphen;
+ const char *checksum;
/* Ideally we would convert hyphens to underscores here, because
* hyphens are not very friendly to D-Bus. However, changing this
@@ -127,9 +128,15 @@ get_gapplication_id_from_id (const char *id)
return g_steal_pointer (&gapplication_id);
/* Split ID into: <normalized-name>-<checksum> */
- split = g_strsplit (id, "-", -1);
- if (g_strv_length (split) != 2) {
- g_warning ("Web app ID %s is broken: must have two hyphens", id);
+ final_hyphen = strrchr (id, '-');
+ if (!final_hyphen) {
+ g_warning ("Web app ID %s is broken: must contain a hyphen", id);
+ return NULL;
+ }
+ checksum = final_hyphen + 1;
+
+ if (*checksum == '\0') {
+ g_warning ("Web app ID %s is broken: should end with checksum, not hyphen", id);
return NULL;
}
@@ -139,7 +146,7 @@ get_gapplication_id_from_id (const char *id)
* existing web apps.
*/
g_clear_pointer (&gapplication_id, g_free);
- gapplication_id = g_strconcat (EPHY_WEB_APP_GAPPLICATION_ID_PREFIX, split[1], NULL);
+ gapplication_id = g_strconcat (EPHY_WEB_APP_GAPPLICATION_ID_PREFIX, checksum, NULL);
if (!g_application_id_is_valid (gapplication_id)) {
g_warning ("Web app ID %s is broken: derived GApplication ID %s is not a valid app ID (is the final
component alphanumeric?)", id, gapplication_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]