summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-12-18 14:56:40 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-12-18 14:56:40 +0000
commita938d8e3862fc0bcf38a73cedb0b8b3716b01936 (patch)
tree1785dd9ae7d4a398a7c62d3c92b13b8039a3e307 /ext
parenta726dcaa99fb4417b1aeab08b630535d3f4024ac (diff)
downloadphp-git-a938d8e3862fc0bcf38a73cedb0b8b3716b01936.tar.gz
Fixed bugs with trimming of spaces
Diffstat (limited to 'ext')
-rw-r--r--ext/filter/filter_private.h31
-rw-r--r--ext/filter/logical_filters.c14
-rw-r--r--ext/filter/tests/042.phpt7
-rw-r--r--ext/filter/tests/044.phpt21
4 files changed, 49 insertions, 24 deletions
diff --git a/ext/filter/filter_private.h b/ext/filter/filter_private.h
index af3aef4fe4..d3b0d07258 100644
--- a/ext/filter/filter_private.h
+++ b/ext/filter/filter_private.h
@@ -88,25 +88,30 @@
|| (id >= FILTER_VALIDATE_ALL && id <= FILTER_VALIDATE_LAST) \
|| id == FILTER_CALLBACK)
+#define RETURN_VALIDATION_FAILED \
+ zval_dtor(value); \
+ if (flags & FILTER_NULL_ON_FAILURE) { \
+ ZVAL_NULL(value); \
+ } else { \
+ ZVAL_FALSE(value); \
+ } \
+ return; \
+
#define PHP_FILTER_TRIM_DEFAULT(p, len, end) { \
- while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\v') { \
+ while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\v' || *p == '\n') { \
p++; \
len--; \
} \
- start = p; \
+ if (len < 1) { \
+ RETURN_VALIDATION_FAILED \
+ } \
+ start = p; \
end = p + len - 1; \
- if (*end == ' ' || *end == '\t' || *end == '\r' || *end == '\v') { \
- unsigned int i; \
- for (i = len - 1; i >= 0; i--) { \
- if (!(p[i] == ' ' || p[i] == '\t' || p[i] == '\r' || p[i] == '\v')) { \
- break; \
- } \
- } \
- i++; \
- p[i] = '\0'; \
- end = p + i - 1; \
- len = (int) (end - p) + 1; \
+ while (*end == ' ' || *end == '\t' || *end == '\r' || *end == '\v' || *end == '\n') { \
+ end--; \
} \
+ *(end + 1) = '\0'; \
+ len = (end - p + 1); \
}
diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c
index 5779cc31c4..7596108f09 100644
--- a/ext/filter/logical_filters.c
+++ b/ext/filter/logical_filters.c
@@ -64,15 +64,6 @@
#define FORMAT_IPV4 4
#define FORMAT_IPV6 6
-#define RETURN_VALIDATION_FAILED \
- zval_dtor(value); \
- if (flags & FILTER_NULL_ON_FAILURE) { \
- ZVAL_NULL(value); \
- } else { \
- ZVAL_FALSE(value); \
- } \
- return; \
-
static int php_filter_parse_int(const char *str, unsigned int str_len, long *ret TSRMLS_DC) { /* {{{ */
long ctx_value = 0;
long sign = 1;
@@ -308,6 +299,9 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
}
str = Z_STRVAL_P(value);
+
+ PHP_FILTER_TRIM_DEFAULT(str, len, end);
+
start = str;
if (len == 1) {
@@ -335,8 +329,6 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
dec_sep = *default_decimal;
}
- PHP_FILTER_TRIM_DEFAULT(str, len, end);
-
if (*str == '-') {
sign = -1;
str++;
diff --git a/ext/filter/tests/042.phpt b/ext/filter/tests/042.phpt
index b295e0698b..62d0d81887 100644
--- a/ext/filter/tests/042.phpt
+++ b/ext/filter/tests/042.phpt
@@ -5,6 +5,13 @@ Combination of strip & sanitize filters
$var = 'XYZ< script>alert(/ext/filter+bypass/);< /script>ABC';
$a = filter_var($var, FILTER_SANITIZE_STRING, array("flags" => FILTER_FLAG_STRIP_LOW));
echo $a . "\n";
+
+$var = 'XYZ<
+script>alert(/ext/filter+bypass/);<
+/script>ABC';
+$a = filter_var($var, FILTER_SANITIZE_STRING, array("flags" => FILTER_FLAG_STRIP_LOW));
+echo $a . "\n";
?>
--EXPECT--
XYZalert(/ext/filter+bypass/);ABC
+XYZalert(/ext/filter+bypass/);ABC
diff --git a/ext/filter/tests/044.phpt b/ext/filter/tests/044.phpt
new file mode 100644
index 0000000000..6aa1114d34
--- /dev/null
+++ b/ext/filter/tests/044.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Integer validation with spaces
+--FILE--
+<?php
+$vals = array(
+"
+ ",
+" ",
+" 123",
+" 123.01 ",
+);
+
+foreach ($vals as $var) {
+ var_dump(filter_var($var, FILTER_VALIDATE_FLOAT));
+}
+?>
+--EXPECT--
+bool(false)
+bool(false)
+float(123)
+float(123.01) \ No newline at end of file