diff options
author | Jan Kneschke <jan@kneschke.de> | 2006-03-04 17:10:47 +0000 |
---|---|---|
committer | Jan Kneschke <jan@kneschke.de> | 2006-03-04 17:10:47 +0000 |
commit | 41ab7d0eb94295ae213801543c196745e4814cd4 (patch) | |
tree | 3c68c82d659a60f327ac4bb5c7a1c5d3e18efdea /src | |
parent | 3400344c358b591f40b61c02d4f733800c0bda6f (diff) | |
download | lighttpd-git-41ab7d0eb94295ae213801543c196745e4814cd4.tar.gz |
allow leading zeros in HTTP/01.01 (fixes #542)
git-svn-id: svn+ssh://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@1025 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src')
-rw-r--r-- | src/request.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/request.c b/src/request.c index 666db3c7..f539c80e 100644 --- a/src/request.c +++ b/src/request.c @@ -368,11 +368,53 @@ int http_request_parse(server *srv, connection *con) { } con->request.http_method = r; - - if (0 == strncmp(proto, "HTTP/1.", sizeof("HTTP/1.") - 1)) { - if (proto[7] == '1') { + + /* + * RFC2616 says: + * + * HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT + * + * */ + if (0 == strncmp(proto, "HTTP/", sizeof("HTTP/") - 1)) { + char * major = proto + sizeof("HTTP/") - 1; + char * minor = strchr(major, '.'); + char *err = NULL; + int major_num = 0, minor_num = 0; + + int invalid_version = 0; + + if (NULL == minor || /* no dot */ + minor == major || /* no major */ + *(minor + 1) == '\0' /* no minor */) { + invalid_version = 1; + } else { + *minor = '\0'; + major_num = strtol(major, &err, 10); + + if (*err != '\0') invalid_version = 1; + + *minor++ = '.'; + minor_num = strtol(minor, &err, 10); + + if (*err != '\0') invalid_version = 1; + } + + if (invalid_version) { + con->http_status = 400; + con->keep_alive = 0; + + if (srv->srvconf.log_request_header_on_error) { + log_error_write(srv, __FILE__, __LINE__, "s", "unknown protocol -> 400"); + log_error_write(srv, __FILE__, __LINE__, "Sb", + "request-header:\n", + con->request.request); + } + return 0; + } + + if (major_num == 1 && minor_num == 1) { con->request.http_version = con->conf.allow_http11 ? HTTP_VERSION_1_1 : HTTP_VERSION_1_0; - } else if (proto[7] == '0') { + } else if (major_num == 1 && minor_num == 0) { con->request.http_version = HTTP_VERSION_1_0; } else { con->http_status = 505; |