aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-10-17 21:32:56 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-10-17 21:32:56 +0000
commit44d84ac1646cf04ccc2c1a736f3c9d1644ccacec (patch)
tree78c8960a291ba0a11548ab34e88a9a7b1bbcee3f /src
parent930f9bd5342e6d514f9ba5b1303762c100621965 (diff)
Avoid typecasting a signed char to an int when using is*() functions, as that
could very well cause a negate number get passed in and thus cause reading outside of the array usually used for this purpose. We avoid this by using the uppercase macro versions introduced just now that does some extra crazy typecasts to avoid byte codes > 127 to cause negative int values.
Diffstat (limited to 'src')
-rw-r--r--src/main.c38
-rw-r--r--src/setup.h14
-rw-r--r--src/urlglob.c10
3 files changed, 39 insertions, 23 deletions
diff --git a/src/main.c b/src/main.c
index af3f4355f..24eec6b34 100644
--- a/src/main.c
+++ b/src/main.c
@@ -380,7 +380,7 @@ static void warnf(struct Configurable *config, const char *fmt, ...)
if(len > (int)WARN_TEXTWIDTH) {
int cut = WARN_TEXTWIDTH-1;
- while(!isspace((int)ptr[cut]) && cut) {
+ while(!ISSPACE(ptr[cut]) && cut) {
cut--;
}
@@ -933,7 +933,7 @@ static int formparse(struct Configurable *config,
while(ptr && (FORM_FILE_SEPARATOR!= *ptr)) {
/* pass all white spaces */
- while(isspace((int)*ptr))
+ while(ISSPACE(*ptr))
ptr++;
if(curlx_strnequal("type=", ptr, 5)) {
@@ -1155,7 +1155,7 @@ static void cleanarg(char *str)
static int str2num(long *val, char *str)
{
int retcode = 0;
- if(isdigit((int)*str))
+ if(ISDIGIT(*str))
*val = atoi(str);
else
retcode = 1; /* badness */
@@ -1961,7 +1961,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
if(ptr &&
(ptr == &nextarg[1]) &&
(nextarg[2] == '\\' || nextarg[2] == '/') &&
- (isalpha((int)nextarg[0])) )
+ (ISALPHA(nextarg[0])) )
/* colon in the second column, followed by a backslash, and the
first character is an alphabetic letter:
@@ -2463,7 +2463,7 @@ static int parseconfig(const char *filename,
int lineno=0;
bool alloced_param;
-#define isseparator(x) (((x)=='=') || ((x) == ':'))
+#define ISSEP(x) (((x)=='=') || ((x) == ':'))
while (NULL != (aline = my_get_line(file))) {
lineno++;
@@ -2471,7 +2471,7 @@ static int parseconfig(const char *filename,
alloced_param=FALSE;
/* lines with # in the fist column is a comment! */
- while(*line && isspace((int)*line))
+ while(*line && ISSPACE(*line))
line++;
switch(*line) {
@@ -2487,7 +2487,7 @@ static int parseconfig(const char *filename,
/* the option keywords starts here */
option = line;
- while(*line && !isspace((int)*line) && !isseparator(*line))
+ while(*line && !ISSPACE(*line) && !ISSEP(*line))
line++;
/* ... and has ended here */
@@ -2499,7 +2499,7 @@ static int parseconfig(const char *filename,
#endif
/* pass spaces and separator(s) */
- while(*line && (isspace((int)*line) || isseparator(*line)))
+ while(*line && (ISSPACE(*line) || ISSEP(*line)))
line++;
/* the parameter starts here (unless quoted) */
@@ -2544,7 +2544,7 @@ static int parseconfig(const char *filename,
}
else {
param=line; /* parameter starts here */
- while(*line && !isspace((int)*line))
+ while(*line && !ISSPACE(*line))
line++;
*line=0; /* zero terminate */
}
@@ -2852,7 +2852,8 @@ convert_from_network(char *buffer, size_t length)
}
static
-char convert_char(curl_infotype infotype, char this_char) {
+char convert_char(curl_infotype infotype, char this_char)
+{
/* determine how this specific character should be displayed */
switch(infotype) {
case CURLINFO_DATA_IN:
@@ -2863,24 +2864,25 @@ char convert_char(curl_infotype infotype, char this_char) {
if ((this_char >= 0x20) && (this_char < 0x7f)) {
/* printable ASCII hex value: convert to host encoding */
convert_from_network(&this_char, 1);
- } else {
+ }
+ else {
/* non-printable ASCII, use a replacement character */
- return(UNPRINTABLE_CHAR);
+ return UNPRINTABLE_CHAR;
}
/* fall through to default */
default:
/* treat as host encoding */
- if (isprint(this_char)
- && (this_char != '\t')
- && (this_char != '\r')
- && (this_char != '\n')) {
+ if (ISPRINT(this_char)
+ && (this_char != '\t')
+ && (this_char != '\r')
+ && (this_char != '\n')) {
/* printable characters excluding tabs and line end characters */
- return(this_char);
+ return this_char;
}
break;
}
/* non-printable, use a replacement character */
- return(UNPRINTABLE_CHAR);
+ return UNPRINTABLE_CHAR;
}
#endif /* CURL_DOES_CONVERSIONS */
diff --git a/src/setup.h b/src/setup.h
index 1acd19e85..a8f636974 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -184,4 +184,16 @@ int fileno( FILE *stream);
#define strdup(ptr) curlx_strdup(ptr)
#endif
+#ifndef ISSPACE
+/* typecasting craze to avoid negative number inputs to these macros */
+/* copied from lib/setup.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)))
+#endif
+
#endif /* __SRC_CURL_SETUP_H */
diff --git a/src/urlglob.c b/src/urlglob.c
index d5d3f4eae..ba4fb1eae 100644
--- a/src/urlglob.c
+++ b/src/urlglob.c
@@ -177,7 +177,7 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
/* patterns 0,1,2,... correspond to size=1,3,5,... */
++glob->size;
- if (isalpha((int)*pattern)) { /* character range detected */
+ if (ISALPHA(*pattern)) { /* character range detected */
char min_c;
char max_c;
@@ -205,7 +205,7 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c;
pat->content.CharRange.max_c = max_c;
}
- else if (isdigit((int)*pattern)) { /* numeric range detected */
+ else if (ISDIGIT(*pattern)) { /* numeric range detected */
int min_n;
int max_n;
@@ -229,9 +229,11 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
if (*pattern == '0') { /* leading zero specified */
c = pattern;
- while (isdigit((int)*c++))
+ while (ISDIGIT(*c)) {
+ c++;
++pat->content.NumRange.padlength; /* padding length is set for all
instances of this pattern */
+ }
}
}
@@ -498,7 +500,7 @@ char *glob_match_url(char *filename, URLGlob *glob)
return NULL; /* major failure */
while (*filename) {
- if (*filename == '#' && isdigit((int)filename[1])) {
+ if (*filename == '#' && ISDIGIT(filename[1])) {
unsigned long i;
char *ptr = filename;
unsigned long num = strtoul(&filename[1], &filename, 10);