Commit 0e3784d1 authored by Bastien Nocera's avatar Bastien Nocera
Browse files

Merge branch 'ipod-afc-crash-fix' into 'master'

ipod: fix crash by handling 24 character uuids in afc uri

Closes #1760

See merge request !63
parents abff20df 3aaeed81
Pipeline #277931 passed with stage
in 10 minutes and 7 seconds
......@@ -141,5 +141,8 @@ widgets/test-rb-segmented-bar
widgets/test-uri-dialog
plugins/audiocd/test-cd
plugins/ipod/test-ipod
plugins/rb/rbconfig.py
plugins/*/*-resources.c
plugins/*/*.trs
plugins/*/*.log
......@@ -40,6 +40,22 @@ AM_CPPFLAGS = \
$(RHYTHMBOX_CFLAGS) \
$(IPOD_CFLAGS)
if HAVE_CHECK
noinst_PROGRAMS = test-ipod
TESTS = test-ipod
test_ipod_SOURCES = \
test-ipod.c \
rb-ipod-helpers.c \
rb-ipod-helpers.h
test_ipod_LDADD = \
$(CHECK_LIBS) \
$(RHYTHMBOX_LIBS) \
$(top_builddir)/shell/librhythmbox-core.la \
$(IPOD_LIBS)
endif
plugin_in_files = ipod.plugin.in
%.plugin: %.plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
......
......@@ -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;
......
......@@ -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 */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2021 The Rhythmbox authors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The Rhythmbox authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Rhythmbox. This permission is above and beyond the permissions granted
* by the GPL license by which Rhythmbox is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <locale.h>
#include "rb-util.h"
#include "rb-debug.h"
#include "rb-ipod-helpers.h"
typedef struct {
const char *uri;
AfcUriStatus status;
} AfcTestData;
AfcTestData afc_test_data[] = {
{ "afc://aaaaaaaaaa1234567890bbbb:1", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbb:10", AFC_URI_PORT_UNKNOWN },
{ "afc://aaaaaaaaaa1234567890bbbb:3", AFC_URI_NOT_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbb:", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbb", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbb/", AFC_URI_IS_IPOD },
{ "afc://12345678-AAAAAAAAAAAAAAAA:1/", AFC_URI_IS_IPOD },
{ "afc://12345678-AAAAAAAAAAAAAAAA:1", AFC_URI_IS_IPOD },
{ "afc://12345678-AAAAAAAAAAAAAAAA:10/", AFC_URI_PORT_UNKNOWN },
{ "afc://12345678-AAAAAAAAAAAAAAAA:3", AFC_URI_NOT_IPOD },
{ "afc://12345678-AAAAAAAAAAAAAAAA:3/", AFC_URI_NOT_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb1234567890:1", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb1234567890:10", AFC_URI_PORT_UNKNOWN },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb1234567890:3", AFC_URI_NOT_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb1234567890:", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb1234567890", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb1234567890/", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb12345678901:1", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb12345678901:10", AFC_URI_PORT_UNKNOWN },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb12345678901:3", AFC_URI_NOT_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb12345678901:", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb12345678901", AFC_URI_IS_IPOD },
{ "afc://aaaaaaaaaa1234567890bbbbbbbbbb12345678901/", AFC_URI_IS_IPOD }
};
static void
test_afc_uri_is_ipod (void)
{
int i;
AfcUriStatus status;
for (i = 0; i < G_N_ELEMENTS (afc_test_data); i++) {
status = rb_ipod_helpers_afc_uri_parse (afc_test_data[i].uri);
if (status != afc_test_data[i].status) {
g_test_message ("URI %s returned %d (expected: %d)",
afc_test_data[i].uri,
status,
afc_test_data[i].status);
}
g_assert_cmpint (status, ==, afc_test_data[i].status);
}
}
int
main (int argc, char **argv)
{
int ret;
/* init stuff */
rb_profile_start ("rb-ipod-helpers test suite");
rb_threads_init ();
setlocale (LC_ALL, "");
rb_debug_init (TRUE);
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("https://gitlab.gnome.org/GNOME/rhythmbox/");
g_test_add_func ("/ipod/uri", test_afc_uri_is_ipod);
ret = g_test_run ();
rb_profile_end ("rb-ipod-helpers test suite");
return ret;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment