Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse session-id header case-insensitively #765

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ set(NEEDED_FUNCTIONS
pread
pwrite
statvfs
strcasestr
strlcpy
strsep
syslog
Expand Down
3 changes: 3 additions & 0 deletions Transmission.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,7 @@
"-DHAVE_ASPRINTF",
"-DHAVE_LIBGEN",
"-DHAVE_STRCASECMP",
"-DHAVE_STRCASESTR",
"-DHAVE_ZLIB",
"-DHAVE_ICONV",
);
Expand Down Expand Up @@ -3124,6 +3125,7 @@
"-DHAVE_ASPRINTF",
"-DHAVE_LIBGEN",
"-DHAVE_STRCASECMP",
"-DHAVE_STRCASESTR",
"-DHAVE_ZLIB",
"-DHAVE_ICONV",
);
Expand Down Expand Up @@ -3352,6 +3354,7 @@
"-DHAVE_ASPRINTF",
"-DHAVE_LIBGEN",
"-DHAVE_STRCASECMP",
"-DHAVE_STRCASESTR",
"-DHAVE_ZLIB",
"-DHAVE_ICONV",
);
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ AC_HEADER_STDC
AC_HEADER_TIME

AC_CHECK_HEADERS([xlocale.h])
AC_CHECK_FUNCS([iconv pread pwrite lrintf strlcpy daemon dirname basename canonicalize_file_name strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign statvfs htonll ntohll mkdtemp uselocale _configthreadlocale])
AC_CHECK_FUNCS([iconv pread pwrite lrintf strlcpy daemon dirname basename canonicalize_file_name strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign statvfs htonll ntohll mkdtemp uselocale _configthreadlocale strcasestr])
AC_PROG_INSTALL
AC_PROG_MAKE_SET
ACX_PTHREAD
Expand Down
4 changes: 4 additions & 0 deletions libtransmission/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ if(ICONV_FOUND)
target_link_libraries(${TR_NAME} ${ICONV_LIBRARIES})
endif()

if(WIN32)
target_link_libraries(${TR_NAME} shlwapi)
endif()

if(ENABLE_TESTS)
add_library(${TR_NAME}-test STATIC
libtransmission-test.c
Expand Down
2 changes: 1 addition & 1 deletion libtransmission/rpc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void handle_upload(struct evhttp_request* req, struct tr_rpc_server* serv
{
struct tr_mimepart* p = tr_ptrArrayNth(&parts, i);

if (tr_memmem(p->headers, p->headers_len, TR_RPC_SESSION_ID_HEADER, strlen(TR_RPC_SESSION_ID_HEADER)) != NULL)
if (tr_strcasestr(p->headers, TR_RPC_SESSION_ID_HEADER) != NULL)
{
char const* ours = get_current_session_id(server);
size_t const ourlen = strlen(ours);
Expand Down
18 changes: 18 additions & 0 deletions libtransmission/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ws2tcpip.h> /* WSAStartup() */
#include <windows.h> /* Sleep(), GetSystemTimeAsFileTime(), GetEnvironmentVariable() */
#include <shellapi.h> /* CommandLineToArgv() */
#include <shlwapi.h> /* StrStrIA() */
#else
#include <sys/time.h>
#include <unistd.h> /* getpagesize() */
Expand Down Expand Up @@ -456,6 +457,23 @@ char const* tr_memmem(char const* haystack, size_t haystacklen, char const* need
#endif
}

char const* tr_strcasestr(char const* haystack, char const* needle)
{
#ifdef HAVE_STRCASESTR

return strcasestr(haystack, needle);

#elif defined(_WIN32)

return StrStrIA(haystack, needle);

#else

#error please open a PR to implement tr_strcasestr() for your platform

#endif
}
LaserEyess marked this conversation as resolved.
Show resolved Hide resolved

char* tr_strdup_printf(char const* fmt, ...)
{
va_list ap;
Expand Down
3 changes: 2 additions & 1 deletion utils/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string.h> /* strcmp */

#include <event2/buffer.h>
#include <event2/util.h>

#define CURL_DISABLE_TYPECHECK /* otherwise -Wunreachable-code goes insane */
#include <curl/curl.h>
Expand Down Expand Up @@ -792,7 +793,7 @@ static size_t parseResponseHeader(void* ptr, size_t size, size_t nmemb, void* st
char const* key = TR_RPC_SESSION_ID_HEADER ": ";
size_t const key_len = strlen(key);

if (line_len >= key_len && memcmp(line, key, key_len) == 0)
if (line_len >= key_len && evutil_ascii_strncasecmp(line, key, key_len) == 0)
ckerr marked this conversation as resolved.
Show resolved Hide resolved
{
char const* begin = line + key_len;
char const* end = begin;
Expand Down