release 2.4.0
[m6w6/ext-http] / php_http_version.c
index fbe94118cf53532bc603b52fbe46f160f14a3951..7adef9d3c897ce66f5923b981c74bd3b46a992d0 100644 (file)
@@ -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);
                                }
                        }
                }