summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-02-24 10:03:30 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-02-24 10:03:30 +0100
commit8d451fd24e37d124ea371e65b98d4e829be24b3e (patch)
tree7097172778f717c5037b11aad1ed984368b3e0e4 /ext/standard
parente855b286c87071ae4c00004ccefabb771102ccb1 (diff)
parent3d9c02364db62a6d8e27947ffe47dbfaad644efe (diff)
downloadphp-git-8d451fd24e37d124ea371e65b98d4e829be24b3e.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Reduce code duplication in HTTP header checks
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/http_fopen_wrapper.c87
1 files changed, 25 insertions, 62 deletions
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
index ffdb53ccbf..966890ac0b 100644
--- a/ext/standard/http_fopen_wrapper.c
+++ b/ext/standard/http_fopen_wrapper.c
@@ -105,6 +105,17 @@ static inline void strip_header(char *header_bag, char *lc_header_bag,
}
}
+static zend_bool check_has_header(const char *headers, const char *header) {
+ const char *s = headers;
+ while ((s = strstr(s, header))) {
+ if (s == headers || *(s-1) == '\r' || *(s-1) == '\n' || *(s-1) == '\t' || *(s-1) == ' ') {
+ return 1;
+ }
+ s++;
+ }
+ return 0;
+}
+
static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
const char *path, const char *mode, int options, zend_string **opened_path,
php_stream_context *context, int redirect_max, int flags,
@@ -459,74 +470,26 @@ finish:
strip_header(user_headers, t, "content-type:");
}
- s = t;
- while ((s = strstr(s, "user-agent:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_USER_AGENT;
- break;
- }
- s++;
+ if (check_has_header(t, "user-agent:")) {
+ have_header |= HTTP_HEADER_USER_AGENT;
}
-
- s = t;
- while ((s = strstr(s, "host:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_HOST;
- break;
- }
- s++;
+ if (check_has_header(t, "host:")) {
+ have_header |= HTTP_HEADER_HOST;
}
-
- s = t;
- while ((s = strstr(s, "from:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_FROM;
- break;
- }
- s++;
+ if (check_has_header(t, "from:")) {
+ have_header |= HTTP_HEADER_FROM;
}
-
- s = t;
- while ((s = strstr(s, "authorization:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_AUTH;
- break;
- }
- s++;
+ if (check_has_header(t, "authorization:")) {
+ have_header |= HTTP_HEADER_AUTH;
}
-
- s = t;
- while ((s = strstr(s, "content-length:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_CONTENT_LENGTH;
- break;
- }
- s++;
+ if (check_has_header(t, "content-length:")) {
+ have_header |= HTTP_HEADER_CONTENT_LENGTH;
}
-
- s = t;
- while ((s = strstr(s, "content-type:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_TYPE;
- break;
- }
- s++;
+ if (check_has_header(t, "content-type:")) {
+ have_header |= HTTP_HEADER_TYPE;
}
-
- s = t;
- while ((s = strstr(s, "connection:"))) {
- if (s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
- *(s-1) == '\t' || *(s-1) == ' ') {
- have_header |= HTTP_HEADER_CONNECTION;
- break;
- }
- s++;
+ if (check_has_header(t, "connection:")) {
+ have_header |= HTTP_HEADER_CONNECTION;
}
/* remove Proxy-Authorization header */