[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 114/178: ctype: restore character classification fo
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 114/178: ctype: restore character classification for non-ASCII platforms |
Date: |
Wed, 23 May 2018 12:25:49 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit dd7521bcc1b7a6fcb53c31f9bd1192fcc884bd56
Author: Stephan Mühlstrasser <address@hidden>
AuthorDate: Fri Apr 13 14:28:55 2018 +0200
ctype: restore character classification for non-ASCII platforms
With commit 4272a0b0fc49a1ac0ceab5c4a365c9f6ab8bf8e2 curl-speficic
character classification macros and functions were introduced in
curl_ctype.[ch] to avoid dependencies on the locale. This broke curl on
non-ASCII, e.g. EBCDIC platforms. This change restores the previous set
of character classification macros when CURL_DOES_CONVERSIONS is
defined.
Closes #2494
---
lib/curl_ctype.c | 4 ++++
lib/curl_ctype.h | 30 ++++++++++++++++++++++++++++++
lib/http_chunks.c | 15 ++++++++++++++-
lib/transfer.c | 2 +-
4 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/lib/curl_ctype.c b/lib/curl_ctype.c
index 4f5abc207..f57a11dc9 100644
--- a/lib/curl_ctype.c
+++ b/lib/curl_ctype.c
@@ -22,6 +22,8 @@
#include "curl_setup.h"
+#ifndef CURL_DOES_CONVERSIONS
+
#undef _U
#define _U (1<<0) /* upper case */
#undef _L
@@ -120,3 +122,5 @@ int Curl_islower(int c)
return FALSE;
return (ascii[c] & (_L));
}
+
+#endif /* !CURL_DOES_CONVERSIONS */
diff --git a/lib/curl_ctype.h b/lib/curl_ctype.h
index da3bd95a6..1ffecb99a 100644
--- a/lib/curl_ctype.h
+++ b/lib/curl_ctype.h
@@ -22,6 +22,33 @@
*
***************************************************************************/
+#include "curl_setup.h"
+
+#ifdef CURL_DOES_CONVERSIONS
+
+/*
+ * Uppercase macro versions of ANSI/ISO is*() functions/macros which
+ * avoid negative number inputs with argument byte codes > 127.
+ *
+ * For non-ASCII platforms the C library character classification routines
+ * are used despite being locale-dependent, because this is better than
+ * not to work at all.
+ */
+#include <ctype.h>
+
+#define ISSPACE(x) (isspace((int) ((unsigned char)x)))
+#define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
+#define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
+#define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
+#define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
+#define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
+#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 ISASCII(x) (isascii((int) ((unsigned char)x)))
+
+#else
+
int Curl_isspace(int c);
int Curl_isdigit(int c);
int Curl_isalnum(int c);
@@ -42,6 +69,9 @@ int Curl_islower(int c);
#define ISUPPER(x) (Curl_isupper((int) ((unsigned char)x)))
#define ISLOWER(x) (Curl_islower((int) ((unsigned char)x)))
#define ISASCII(x) (((x) >= 0) && ((x) <= 0x80))
+
+#endif
+
#define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
(((unsigned char)x) == '\t'))
diff --git a/lib/http_chunks.c b/lib/http_chunks.c
index 8368eeca6..18dfcb282 100644
--- a/lib/http_chunks.c
+++ b/lib/http_chunks.c
@@ -74,6 +74,19 @@
*/
+#ifdef CURL_DOES_CONVERSIONS
+/* Check for an ASCII hex digit.
+ We avoid the use of ISXDIGIT to accommodate non-ASCII hosts. */
+static bool Curl_isxdigit_ascii(char digit)
+{
+ return (digit >= 0x30 && digit <= 0x39) /* 0-9 */
+ || (digit >= 0x41 && digit <= 0x46) /* A-F */
+ || (digit >= 0x61 && digit <= 0x66); /* a-f */
+}
+#else
+#define Curl_isxdigit_ascii(x) Curl_isxdigit(x)
+#endif
+
void Curl_httpchunk_init(struct connectdata *conn)
{
struct Curl_chunker *chunk = &conn->chunk;
@@ -119,7 +132,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
while(length) {
switch(ch->state) {
case CHUNK_HEX:
- if(Curl_isxdigit(*datap)) {
+ if(Curl_isxdigit_ascii(*datap)) {
if(ch->hexindex < MAXNUM_SIZE) {
ch->hexbuffer[ch->hexindex] = *datap;
datap++;
diff --git a/lib/transfer.c b/lib/transfer.c
index 9712a7f7e..c586c727d 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -1519,7 +1519,7 @@ static void strcpy_url(char *output, const char *url,
bool relative)
left = FALSE;
/* fall through */
default:
- if(*iptr >= 0x80) {
+ if(!ISPRINT(*iptr)) {
snprintf(optr, 4, "%%%02x", *iptr);
optr += 3;
}
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 51/178: Revert "openssl: Don't add verify locations when verifypeer==0", (continued)
- [GNUnet-SVN] [gnurl] 51/178: Revert "openssl: Don't add verify locations when verifypeer==0", gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 73/178: mailmap: add a monnerat fixup [ci skip], gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 64/178: build: cleanup to fix clang warnings/errors, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 56/178: build-openssl.bat: Refer to VS2017 as VC14.1 instead of VC15, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 116/178: strcpy_url: only %-encode values >= 0x80, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 105/178: curl_global_sslset: always provide available backends, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 86/178: winbuild: Support custom devel paths for each dependency, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 100/178: Revert "ftplistparser: keep state between invokes", gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 103/178: curl.1: clarify that options and URLs can be mixed, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 119/178: RELEASE-NOTES: synced, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 114/178: ctype: restore character classification for non-ASCII platforms,
gnunet <=
- [GNUnet-SVN] [gnurl] 115/178: mime: avoid NULL pointer dereference risk, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 129/178: TODO: Support the clienthello extension, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 131/178: KNOWN_BUGS: Connection information when using TCP Fast Open, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 136/178: wolfssl: Fix non-blocking connect, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 76/178: checksrc: Fix typo, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 63/178: examples/sftpuploadresmue: Fix Windows large file seek, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 71/178: travis: build libpsl and make builds use it, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 78/178: vauth: Fix typo, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 81/178: urldata: make service names unconditional, gnunet, 2018/05/23
- [GNUnet-SVN] [gnurl] 67/178: winbuild: fix URL, gnunet, 2018/05/23