input/curl, ...: use strncmp() instead of memcmp() to avoid crash

This commit is contained in:
Max Kellermann 2017-01-03 13:16:29 +01:00
parent 06116382ee
commit 31d77ec580
5 changed files with 11 additions and 11 deletions

View File

@ -433,8 +433,8 @@ CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond)
static InputStream *
input_curl_open(const char *url, Mutex &mutex, Cond &cond)
{
if (memcmp(url, "http://", 7) != 0 &&
memcmp(url, "https://", 8) != 0)
if (strncmp(url, "http://", 7) != 0 &&
strncmp(url, "https://", 8) != 0)
return nullptr;
return CurlInputStream::Open(url, mutex, cond);

View File

@ -274,31 +274,31 @@ try {
static SongEnumerator *
soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond)
{
assert(memcmp(uri, "soundcloud://", 13) == 0);
assert(strncmp(uri, "soundcloud://", 13) == 0);
uri += 13;
char *u = nullptr;
if (memcmp(uri, "track/", 6) == 0) {
if (strncmp(uri, "track/", 6) == 0) {
const char *rest = uri + 6;
u = xstrcatdup("https://api.soundcloud.com/tracks/",
rest, ".json?client_id=",
soundcloud_config.apikey.c_str());
} else if (memcmp(uri, "playlist/", 9) == 0) {
} else if (strncmp(uri, "playlist/", 9) == 0) {
const char *rest = uri + 9;
u = xstrcatdup("https://api.soundcloud.com/playlists/",
rest, ".json?client_id=",
soundcloud_config.apikey.c_str());
} else if (memcmp(uri, "user/", 5) == 0) {
} else if (strncmp(uri, "user/", 5) == 0) {
const char *rest = uri + 5;
u = xstrcatdup("https://api.soundcloud.com/users/",
rest, "/tracks.json?client_id=",
soundcloud_config.apikey.c_str());
} else if (memcmp(uri, "search/", 7) == 0) {
} else if (strncmp(uri, "search/", 7) == 0) {
const char *rest = uri + 7;
u = xstrcatdup("https://api.soundcloud.com/tracks.json?q=",
rest, "&client_id=",
soundcloud_config.apikey.c_str());
} else if (memcmp(uri, "url/", 4) == 0) {
} else if (strncmp(uri, "url/", 4) == 0) {
const char *rest = uri + 4;
/* Translate to soundcloud resolver call. libcurl will automatically
follow the redirect to the right resource. */

View File

@ -389,7 +389,7 @@ NfsStorage::OpenDirectory(const char *uri_utf8)
static Storage *
CreateNfsStorageURI(EventLoop &event_loop, const char *base)
{
if (memcmp(base, "nfs://", 6) != 0)
if (strncmp(base, "nfs://", 6) != 0)
return nullptr;
const char *p = base + 6;

View File

@ -182,7 +182,7 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow)
static Storage *
CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
{
if (memcmp(base, "smb://", 6) != 0)
if (strncmp(base, "smb://", 6) != 0)
return nullptr;
SmbclientInit();

View File

@ -34,7 +34,7 @@ Log(const Domain &domain, gcc_unused LogLevel level, const char *msg)
bool
uri_supported_scheme(const char *uri)
{
return memcmp(uri, "http://", 7) == 0;
return strncmp(uri, "http://", 7) == 0;
}
static constexpr auto music_directory = PATH_LITERAL("/music");