aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-29 17:30:24 +0100
committerMax Kellermann <max@duempel.org>2013-12-29 17:40:51 +0100
commitafc70c120e6b08ac550b107d3bc588262551dae5 (patch)
tree5763c46f48a848d20cf5f93710e323f25d83e54e
parentd7f80eab68b5cb0d2aa90e67fa2bb04b1bbef975 (diff)
downloadmpd-afc70c120e6b08ac550b107d3bc588262551dae5.tar.gz
mpd-afc70c120e6b08ac550b107d3bc588262551dae5.tar.xz
mpd-afc70c120e6b08ac550b107d3bc588262551dae5.zip
util/UriUtil: uri_get_suffix() fails if name begins with dot
A file called ".jpg" is not a JPEG file with an empty name; it is merely a hidden file.
-rw-r--r--src/util/UriUtil.cxx3
-rw-r--r--test/test_util.cxx4
2 files changed, 6 insertions, 1 deletions
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index 7997bd5c9..2609db2cf 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -32,7 +32,8 @@ const char *
uri_get_suffix(const char *uri)
{
const char *suffix = strrchr(uri, '.');
- if (suffix == nullptr)
+ if (suffix == nullptr || suffix == uri ||
+ suffix[-1] == '/' || suffix[-1] == '\\')
return nullptr;
++suffix;
diff --git a/test/test_util.cxx b/test/test_util.cxx
index 2ff303540..a472391a3 100644
--- a/test/test_util.cxx
+++ b/test/test_util.cxx
@@ -29,6 +29,10 @@ public:
"jpg"));
CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"),
"jpg"));
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix(".jpg"));
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix("/foo/.jpg"));
}
void TestRemoveAuth() {