aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2009-01-21 04:42:47 +0000
committerDan Fandrich <dan@coneharvesters.com>2009-01-21 04:42:47 +0000
commit5591550167092c0e5f307b3c2c87f44518e7159f (patch)
tree7fc43fd73fc132099fc7a9c6c740484ad29d4c82 /lib
parent6bb9ef8de4273e0f5f5e499eb61a972b3644f70f (diff)
Fixed a couple more locale-dependent toupper conversions, mainly for
clarity. This does fix one problem that causes ;type=i FTP URLs to fail in the Turkish locale when CURLOPT_PROXY_TRANSFER_MODE is used (test case 561) Added tests 561 and 1092 through 1094 to test various combinations of ;type= and ;mode= URLs that could potentially fail in the Turkish locale.
Diffstat (limited to 'lib')
-rw-r--r--lib/ftp.c3
-rw-r--r--lib/http.c2
-rw-r--r--lib/http_ntlm.c21
-rw-r--r--lib/rawstr.c12
-rw-r--r--lib/rawstr.h2
-rw-r--r--lib/ssluse.c2
-rw-r--r--lib/tftp.c3
-rw-r--r--lib/url.c18
-rw-r--r--lib/url.h1
9 files changed, 38 insertions, 26 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index 53542ecbc..66933d673 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -89,6 +89,7 @@
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
#include "multiif.h"
#include "url.h"
+#include "rawstr.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -4141,7 +4142,7 @@ static CURLcode ftp_setup_connection(struct connectdata * conn)
if(type) {
*type = 0; /* it was in the middle of the hostname */
- command = (char) toupper((int) type[6]);
+ command = Curl_raw_toupper(type[6]);
switch (command) {
case 'A': /* ASCII mode */
diff --git a/lib/http.c b/lib/http.c
index eaa50eeef..b96d51d78 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -2271,7 +2271,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(checkprefix("ftp://", ppath) || checkprefix("ftps://", ppath)) {
char *p = strstr(ppath, ";type=");
if(p && p[6] && p[7] == 0) {
- switch (toupper((int)((unsigned char)p[6]))) {
+ switch (Curl_raw_toupper(p[6])) {
case 'A':
case 'D':
case 'I':
diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c
index afed953e2..869a247a0 100644
--- a/lib/http_ntlm.c
+++ b/lib/http_ntlm.c
@@ -323,7 +323,7 @@ CURLntlm Curl_input_ntlm(struct connectdata *conn,
* Turns a 56 bit key into the 64 bit, odd parity key and sets the key. The
* key schedule ks is also set.
*/
-static void setup_des_key(unsigned char *key_56,
+static void setup_des_key(const unsigned char *key_56,
DES_key_schedule DESKEYARG(ks))
{
DES_cblock key;
@@ -346,9 +346,9 @@ static void setup_des_key(unsigned char *key_56,
* 8 byte plaintext is encrypted with each key and the resulting 24
* bytes are stored in the results array.
*/
-static void lm_resp(unsigned char *keys,
- unsigned char *plaintext,
- unsigned char *results)
+static void lm_resp(const unsigned char *keys,
+ const unsigned char *plaintext,
+ unsigned char *results)
{
DES_key_schedule ks;
@@ -377,17 +377,10 @@ static void mk_lm_hash(struct SessionHandle *data,
static const unsigned char magic[] = {
0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 /* i.e. KGS!@#$% */
};
- unsigned int i;
- size_t len = strlen(password);
-
- if(len > 14)
- len = 14;
-
- for (i=0; i<len; i++)
- pw[i] = (unsigned char)toupper(password[i]);
+ size_t len = CURLMIN(strlen(password), 14);
- for (; i<14; i++)
- pw[i] = 0;
+ Curl_strntoupper((char *)pw, password, len);
+ memset(&pw[len], 0, 14-len);
#ifdef CURL_DOES_CONVERSIONS
/*
diff --git a/lib/rawstr.c b/lib/rawstr.c
index b0fe38b26..795342338 100644
--- a/lib/rawstr.c
+++ b/lib/rawstr.c
@@ -25,9 +25,9 @@
#include "rawstr.h"
-/* Portable toupper (remember EBCDIC). Do not use tupper() because
+/* Portable, consistent toupper (remember EBCDIC). Do not use toupper() because
its behavior is altered by the current locale. */
-static unsigned char my_toupper(unsigned char in)
+char Curl_raw_toupper(char in)
{
switch (in) {
case 'a':
@@ -98,7 +98,7 @@ static unsigned char my_toupper(unsigned char in)
int Curl_raw_equal(const char *first, const char *second)
{
while(*first && *second) {
- if(my_toupper(*first) != my_toupper(*second))
+ if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second))
/* get out of the loop as soon as they don't match */
break;
first++;
@@ -107,13 +107,13 @@ int Curl_raw_equal(const char *first, const char *second)
/* we do the comparison here (possibly again), just to make sure that if the
loop above is skipped because one of the strings reached zero, we must not
return this as a successful match */
- return (my_toupper(*first) == my_toupper(*second));
+ return (Curl_raw_toupper(*first) == Curl_raw_toupper(*second));
}
int Curl_raw_nequal(const char *first, const char *second, size_t max)
{
while(*first && *second && max) {
- if(my_toupper(*first) != my_toupper(*second)) {
+ if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) {
break;
}
max--;
@@ -123,6 +123,6 @@ int Curl_raw_nequal(const char *first, const char *second, size_t max)
if(0 == max)
return 1; /* they are equal this far */
- return my_toupper(*first) == my_toupper(*second);
+ return Curl_raw_toupper(*first) == Curl_raw_toupper(*second);
}
diff --git a/lib/rawstr.h b/lib/rawstr.h
index 58eec7727..46fb60929 100644
--- a/lib/rawstr.h
+++ b/lib/rawstr.h
@@ -35,6 +35,8 @@
int Curl_raw_equal(const char *first, const char *second);
int Curl_raw_nequal(const char *first, const char *second, size_t max);
+char Curl_raw_toupper(char in);
+
/* checkprefix() is a shorter version of the above, used when the first
argument is zero-byte terminated */
#define checkprefix(a,b) Curl_raw_nequal(a,b,strlen(a))
diff --git a/lib/ssluse.c b/lib/ssluse.c
index 7bf549f53..ec3c53157 100644
--- a/lib/ssluse.c
+++ b/lib/ssluse.c
@@ -994,7 +994,7 @@ static int hostmatch(const char *hostname, const char *pattern)
break;
}
- if(toupper(c) != toupper(*hostname++))
+ if(Curl_raw_toupper(c) != Curl_raw_toupper(*hostname++))
break;
}
return HOST_NOMATCH;
diff --git a/lib/tftp.c b/lib/tftp.c
index 4f53580fd..9020a1a23 100644
--- a/lib/tftp.c
+++ b/lib/tftp.c
@@ -72,6 +72,7 @@
#include "strerror.h"
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
#include "url.h"
+#include "rawstr.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -904,7 +905,7 @@ static CURLcode tftp_setup_connection(struct connectdata * conn)
if(type) {
*type = 0; /* it was in the middle of the hostname */
- command = (char) toupper((int) type[6]);
+ command = Curl_raw_toupper(type[6]);
switch (command) {
case 'A': /* ASCII mode */
diff --git a/lib/url.c b/lib/url.c
index 0145d4935..47d2af342 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -230,6 +230,21 @@ void Curl_safefree(void *ptr)
free(ptr);
}
+/* Copy an upper case version of the string from src to dest. The
+ * strings may overlap. No more than n characters of the string are copied
+ * (including any NUL) and the destination string will NOT be
+ * NUL-terminated if that limit is reached.
+ */
+void Curl_strntoupper(char *dest, const char *src, size_t n)
+{
+ if (n < 1)
+ return;
+
+ do {
+ *dest++ = Curl_raw_toupper(*src);
+ } while (*src++ && --n);
+}
+
static void close_connections(struct SessionHandle *data)
{
/* Loop through all open connections and kill them one by one */
@@ -3441,8 +3456,7 @@ static char *detect_proxy(struct connectdata *conn)
*/
if(!prox && !Curl_raw_equal("http_proxy", proxy_env)) {
/* There was no lowercase variable, try the uppercase version: */
- for(envp = proxy_env; *envp; envp++)
- *envp = (char)toupper((int)*envp);
+ Curl_strntoupper(proxy_env, proxy_env, sizeof(proxy_env));
prox=curl_getenv(proxy_env);
}
diff --git a/lib/url.h b/lib/url.h
index 2c60507c3..ec4da99c2 100644
--- a/lib/url.h
+++ b/lib/url.h
@@ -48,6 +48,7 @@ CURLcode Curl_protocol_connect(struct connectdata *conn, bool *done);
CURLcode Curl_protocol_connecting(struct connectdata *conn, bool *done);
CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done);
void Curl_safefree(void *ptr);
+void Curl_strntoupper(char *dest, const char *src, size_t n);
/* create a connection cache */
struct conncache *Curl_mk_connc(int type, long amount);