[rhythmbox: 1/3] ipod: Fix crash by handling 24 character UDIDs in afc uri




commit b95a38ebfcc7c6c7136a84efe2a7990d47cf997c
Author: crvi <crvisqr gmail com>
Date:   Thu Jun 18 02:41:32 2020 +0530

    ipod: Fix crash by handling 24 character UDIDs in afc uri
    
    See https://github.com/libimobiledevice/libimobiledevice/issues/874#issuecomment-555105676
    
    Fixes: #1760

 plugins/ipod/rb-ipod-helpers.c | 37 +++++++++++++++++++++++++++++--------
 plugins/ipod/rb-ipod-helpers.h | 19 +++++++++++++++++++
 2 files changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/plugins/ipod/rb-ipod-helpers.c b/plugins/ipod/rb-ipod-helpers.c
index 25d624be1..d06ab1a31 100644
--- a/plugins/ipod/rb-ipod-helpers.c
+++ b/plugins/ipod/rb-ipod-helpers.c
@@ -37,6 +37,7 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <gpod/itdb.h>
+#include <libsoup/soup.h>
 
 #include "rb-ipod-helpers.h"
 #include "rb-util.h"
@@ -327,6 +328,31 @@ rb_ipod_helpers_mount_has_ipod_db (GMount *mount)
         return result;
 }
 
+AfcUriStatus
+rb_ipod_helpers_afc_uri_parse (const gchar *uri_str)
+{
+       g_autoptr(SoupURI) uri = NULL;
+       guint port;
+
+       uri = soup_uri_new (uri_str);
+       if (!uri) {
+               rb_debug ("Invalid afc uri: '%s'", uri_str);
+               return AFC_URI_INVALID;
+       }
+       /* Skip scheme check, as it's done in the caller */
+       port = soup_uri_get_port (uri);
+
+       if (port == 0) {
+               rb_debug ("afc uri '%s' is an ipod", uri_str);
+               return AFC_URI_IS_IPOD;
+       } else if (port >= VIRTUAL_PORT_MIN && port <= VIRTUAL_PORT_MAX) {
+               rb_debug ("afc uri '%s' %s ipod", uri_str, port == VIRTUAL_PORT_AFC ? "is" : "is not");
+               return (port == VIRTUAL_PORT_AFC ? AFC_URI_IS_IPOD : AFC_URI_NOT_IPOD);
+       }
+       rb_debug ("Unknown port %d in afc uri: '%s'", port, uri_str);
+       return AFC_URI_PORT_UNKNOWN;
+}
+
 gboolean
 rb_ipod_helpers_is_ipod (GMount *mount, MPIDDevice *device_info)
 {
@@ -354,15 +380,10 @@ rb_ipod_helpers_is_ipod (GMount *mount, MPIDDevice *device_info)
 
                        if (g_file_has_uri_scheme (root, "afc") != FALSE) {
                                gchar *uri;
+                               AfcUriStatus status;
                                uri = g_file_get_uri (root);
-                               /* afc://<40 chars>:stuff */
-                               g_assert (strlen (uri) >= 46);
-                               if (uri[6 + 40] == ':' &&
-                                   uri[6 + 40 + 1] != '1') {
-                                       result = FALSE;
-                               } else {
-                                       result = TRUE;
-                               }
+                               status = rb_ipod_helpers_afc_uri_parse (uri);
+                               result = (status == AFC_URI_IS_IPOD);
                                g_free (uri);
                        } else {
                                gchar *mount_point;
diff --git a/plugins/ipod/rb-ipod-helpers.h b/plugins/ipod/rb-ipod-helpers.h
index 7409c9922..e8ccbbff4 100644
--- a/plugins/ipod/rb-ipod-helpers.h
+++ b/plugins/ipod/rb-ipod-helpers.h
@@ -33,6 +33,24 @@
 
 #include "mediaplayerid.h"
 
+/* From gvfs/daemon/gvfsbackendafc.c */
+typedef enum
+{
+       VIRTUAL_PORT_AFC = 1,
+       VIRTUAL_PORT_AFC_JAILBROKEN = 2,
+       VIRTUAL_PORT_APPS = 3,
+       VIRTUAL_PORT_MIN = VIRTUAL_PORT_AFC,
+       VIRTUAL_PORT_MAX = VIRTUAL_PORT_APPS
+} VirtualPort;
+
+typedef enum
+{
+       AFC_URI_INVALID = 0,
+       AFC_URI_PORT_UNKNOWN,
+       AFC_URI_NOT_IPOD,
+       AFC_URI_IS_IPOD
+} AfcUriStatus;
+
 G_BEGIN_DECLS
 void rb_ipod_helpers_fill_model_combo (GtkWidget *combo, const char *mountpoint);
 
@@ -41,6 +59,7 @@ guint64 rb_ipod_helpers_get_free_space (const char *mountpoint);
 char *rb_ipod_helpers_get_device (RBSource *source);
 gboolean rb_ipod_helpers_is_ipod (GMount *mount, MPIDDevice *device_info);
 gboolean rb_ipod_helpers_needs_init (GMount *mount);
+AfcUriStatus rb_ipod_helpers_afc_uri_parse (const gchar *uri);
 G_END_DECLS
 
 #endif /* __RB_IPOD_HELPERS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]