[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 142/178: URL: fix ASCII dependency in strcpy_url an
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 142/178: URL: fix ASCII dependency in strcpy_url and strlen_url |
Date: |
Wed, 23 May 2018 12:26:17 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 7f41432c191c70f7f782802cd17e95e87a9a7671
Author: Stephan Mühlstrasser <address@hidden>
AuthorDate: Thu Apr 26 10:15:26 2018 +0200
URL: fix ASCII dependency in strcpy_url and strlen_url
Commit 3c630f9b0af097663a64e5c875c580aa9808a92b partially reverted the
changes from commit dd7521bcc1b7a6fcb53c31f9bd1192fcc884bd56 because of
the problem that strcpy_url() was modified unilaterally without also
modifying strlen_url(). As a consequence strcpy_url() was again
depending on ASCII encoding.
This change fixes strlen_url() and strcpy_url() in parallel to use a
common host-encoding independent criterion for deciding whether an URL
character must be %-escaped.
Closes #2535
---
lib/curl_ctype.c | 7 +++++++
lib/curl_ctype.h | 3 +++
lib/transfer.c | 14 ++++++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/lib/curl_ctype.c b/lib/curl_ctype.c
index f57a11dc9..1a47fb5e6 100644
--- a/lib/curl_ctype.c
+++ b/lib/curl_ctype.c
@@ -123,4 +123,11 @@ int Curl_islower(int c)
return (ascii[c] & (_L));
}
+int Curl_iscntrl(int c)
+{
+ if((c < 0) || (c >= 0x80))
+ return FALSE;
+ return (ascii[c] & (_C));
+}
+
#endif /* !CURL_DOES_CONVERSIONS */
diff --git a/lib/curl_ctype.h b/lib/curl_ctype.h
index 1ffecb99a..6e94bb1b4 100644
--- a/lib/curl_ctype.h
+++ b/lib/curl_ctype.h
@@ -45,6 +45,7 @@
#define ISPRINT(x) (isprint((int) ((unsigned char)x)))
#define ISUPPER(x) (isupper((int) ((unsigned char)x)))
#define ISLOWER(x) (islower((int) ((unsigned char)x)))
+#define ISCNTRL(x) (iscntrl((int) ((unsigned char)x)))
#define ISASCII(x) (isascii((int) ((unsigned char)x)))
#else
@@ -58,6 +59,7 @@ int Curl_isprint(int c);
int Curl_isalpha(int c);
int Curl_isupper(int c);
int Curl_islower(int c);
+int Curl_iscntrl(int c);
#define ISSPACE(x) (Curl_isspace((int) ((unsigned char)x)))
#define ISDIGIT(x) (Curl_isdigit((int) ((unsigned char)x)))
@@ -68,6 +70,7 @@ int Curl_islower(int c);
#define ISPRINT(x) (Curl_isprint((int) ((unsigned char)x)))
#define ISUPPER(x) (Curl_isupper((int) ((unsigned char)x)))
#define ISLOWER(x) (Curl_islower((int) ((unsigned char)x)))
+#define ISCNTRL(x) (Curl_iscntrl((int) ((unsigned char)x)))
#define ISASCII(x) (((x) >= 0) && ((x) <= 0x80))
#endif
diff --git a/lib/transfer.c b/lib/transfer.c
index 9712a7f7e..5c8eb31d3 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -1447,6 +1447,16 @@ static const char *find_host_sep(const char *url)
}
/*
+ * Decide in an encoding-independent manner whether a character in an
+ * URL must be escaped. The same criterion must be used in strlen_url()
+ * and strcpy_url().
+ */
+static bool urlchar_needs_escaping(int c)
+{
+ return !(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c));
+}
+
+/*
* strlen_url() returns the length of the given URL if the spaces within the
* URL were properly URL encoded.
* URL encoding should be skipped for host names, otherwise IDN resolution
@@ -1474,7 +1484,7 @@ static size_t strlen_url(const char *url, bool relative)
left = FALSE;
/* fall through */
default:
- if(*ptr >= 0x80)
+ if(urlchar_needs_escaping(*ptr))
newlen += 2;
newlen++;
break;
@@ -1519,7 +1529,7 @@ static void strcpy_url(char *output, const char *url,
bool relative)
left = FALSE;
/* fall through */
default:
- if(*iptr >= 0x80) {
+ if(urlchar_needs_escaping(*iptr)) {
snprintf(optr, 4, "%%%02x", *iptr);
optr += 3;
}
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 110/178: Revert "ftplistparser: keep state between invokes", (continued)
- [GNUnet-SVN] [gnurl] 110/178: Revert "ftplistparser: keep state between invokes", gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 126/178: CURLINFO_PROTOCOL.3: mention the existing defined names, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 113/178: ftplistparser: keep state between invokes, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 124/178: checksrc: force indentation of lines after an else, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 107/178: ftplistparser: renamed some members and variables, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 108/178: ftplistparser: keep state between invokes, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 132/178: KNOWN_BUGS: --upload-file . hang if delay in STDIN, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 134/178: KNOWN_BUGS: Client cert with Issuer DN differs between backends, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 130/178: travis: enable libssh2 on both macos and Linux, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 127/178: tests: provide 'manual' as a feature to optionally require, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 142/178: URL: fix ASCII dependency in strcpy_url and strlen_url,
gnunet <=
- [GNUnet-SVN] [gnurl] 161/178: http: restore buffer pointer when bad response-line is parsed, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 133/178: KNOWN_BUGS: Passive transfer tries only one IP address, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 145/178: travis: add an mbedtls build, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 156/178: openssl: change FILE ops to BIO ops, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 139/178: Revert "TODO: remove configure --disable-pthreads", gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 140/178: RELEASE-NOTES: synced, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 174/178: http2: remove unused variable, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 176/178: THANKS: added people from the curl 7.60.0 release, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 152/178: URLs: fix one more http url, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 138/178: vtls: don't define MD5_DIGEST_LENGTH for wolfssl, gnunet, 2018/05/23