summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@redhat.com>2021-12-16 08:05:21 -0600
committerMichael Catanzaro <mcatanzaro@redhat.com>2021-12-16 08:23:52 -0600
commite0d464a3fe087c024810e7ccbc96d06309199fc4 (patch)
tree08644a6b534c6b88706e9e3093d89286d5d1c0d2
parenta2928c7c71851794b07d8aa825161a2d51cb50da (diff)
downloadepiphany-e0d464a3fe087c024810e7ccbc96d06309199fc4.tar.gz
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.
-rw-r--r--lib/ephy-web-app-utils.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index 51209b764..833dcdd7a 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -109,8 +109,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
@@ -126,9 +127,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;
}
@@ -138,7 +145,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);