From d35487e50c185a7198944ef89adcd0a7348d474f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 1 May 2012 19:47:05 +0100 Subject: [PATCH] uri: require URI protocol bit to be at least 3 characters to be valid We want to return FALSE when run on a windows-style file path. https://bugzilla.gnome.org/show_bug.cgi?id=674296 --- gst/gsturi.c | 4 ++-- tests/check/gst/gsturi.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gst/gsturi.c b/gst/gsturi.c index 75c3440..afe2907 100644 --- a/gst/gsturi.c +++ b/gst/gsturi.c @@ -313,7 +313,7 @@ gst_uri_protocol_is_valid (const gchar * protocol) gst_uri_protocol_check_internal (protocol, &endptr); - return *endptr == '\0' && endptr != protocol; + return *endptr == '\0' && ((gsize) (endptr - protocol)) >= 3; } /** @@ -334,7 +334,7 @@ gst_uri_is_valid (const gchar * uri) gst_uri_protocol_check_internal (uri, &endptr); - return *endptr == ':'; + return *endptr == ':' && ((gsize) (endptr - uri)) >= 3; } /** diff --git a/tests/check/gst/gsturi.c b/tests/check/gst/gsturi.c index ca6c2c9..4eee4f1 100644 --- a/tests/check/gst/gsturi.c +++ b/tests/check/gst/gsturi.c @@ -105,6 +105,30 @@ GST_END_TEST; #endif /* G_OS_WIN32 */ +GST_START_TEST (test_uri_misc) +{ + /* require at least three characters for the protocol */ + fail_if (gst_uri_is_valid ("B:\\foo.txt")); + fail_if (gst_uri_is_valid ("B:/foo.txt")); + fail_if (gst_uri_is_valid ("B://foo.txt")); + fail_if (gst_uri_is_valid ("B:foo.txt")); + + fail_if (gst_uri_is_valid ("AB:\\foo.txt")); + fail_if (gst_uri_is_valid ("AB:/foo.txt")); + fail_if (gst_uri_is_valid ("AB://foo.txt")); + fail_if (gst_uri_is_valid ("AB:foo.txt")); + + fail_unless (gst_uri_is_valid ("ABC:/foo.txt")); + fail_unless (gst_uri_is_valid ("ABC://foo.txt")); + fail_unless (gst_uri_is_valid ("ABC:foo.txt")); + + fail_unless (gst_uri_is_valid ("ABCD:/foo.txt")); + fail_unless (gst_uri_is_valid ("ABCD://foo.txt")); + fail_unless (gst_uri_is_valid ("ABCD:foo.txt")); +} + +GST_END_TEST; + static Suite * gst_uri_suite (void) { @@ -116,6 +140,7 @@ gst_uri_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_protocol_case); tcase_add_test (tc_chain, test_uri_get_location); + tcase_add_test (tc_chain, test_uri_misc); #ifdef G_OS_WIN32 tcase_add_test (tc_chain, test_win32_uri); #endif -- 2.7.4