X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_version.c;h=7adef9d3c897ce66f5923b981c74bd3b46a992d0;hp=f4fcfc85367417dee7cb8f711fe39d89f18250b3;hb=046973e332c1475f9bf7717af9d33a75283deb37;hpb=175ff7d5e20362f0215910a6637ec3b59a885693 diff --git a/php_http_version.c b/php_http_version.c index f4fcfc8..7adef9d 100644 --- a/php_http_version.c +++ b/php_http_version.c @@ -27,7 +27,7 @@ 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) { long major, minor; - char separator = 0, *stop = NULL; + char separator = 0; register const char *ptr = str; switch (*ptr) { @@ -40,16 +40,16 @@ php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *st ++ptr; /* no break */ default: - major = strtol(ptr, &stop, 10); - if (stop && stop != ptr && major != LONG_MIN && 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; - minor = strtol(ptr, &stop, 10); - if (minor != LONG_MIN && minor != LONG_MAX) { + minor = *ptr - '0'; + if (minor >= 0 && minor <= 9) { return php_http_version_init(v, major, minor TSRMLS_CC); } }