X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_version.c;h=7adef9d3c897ce66f5923b981c74bd3b46a992d0;hp=fbe94118cf53532bc603b52fbe46f160f14a3951;hb=refs%2Fheads%2Fv2.4.x;hpb=eaa046dc3e6496e523a17c3b786ef27067b9795c diff --git a/php_http_version.c b/php_http_version.c index fbe9411..7adef9d 100644 --- a/php_http_version.c +++ b/php_http_version.c @@ -26,8 +26,8 @@ php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC) { - php_http_version_t tmp; - char separator = 0, *stop = NULL; + long major, minor; + char separator = 0; register const char *ptr = str; switch (*ptr) { @@ -40,17 +40,17 @@ php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *st ++ptr; /* no break */ default: - tmp.major = strtol(ptr, &stop, 10); - if (stop && stop != ptr && tmp.major != LONG_MIN && tmp.major != LONG_MAX) { - separator = *stop; + /* rfc7230#2.6 The HTTP version number consists of two decimal digits separated by a "." (period or decimal point) */ + major = *ptr++ - '0'; + if (major >= 0 && major <= 9) { + separator = *ptr++; if (separator) { if (separator != '.' && separator != ',') { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2); } - ptr = stop + 1; - tmp.minor = strtol(ptr, &stop, 10); - if (tmp.minor != LONG_MIN && tmp.minor != LONG_MAX) { - return php_http_version_init(v, tmp.major, tmp.minor TSRMLS_CC); + minor = *ptr - '0'; + if (minor >= 0 && minor <= 9) { + return php_http_version_init(v, major, minor TSRMLS_CC); } } }