From 5c0128d82d4bd9d706ec36cc2e13cd3492ff3181 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Fri, 4 Jul 2008 16:42:35 +0300 Subject: [PATCH] Bug 1021: initialize version in http_got_header gcc-4.3 -O2 was complaining that http_got_header may use uninitialized version.major and version.minor. That indeed happened with HTTP/0.9 servers, and the PRE_HTTP_1_1(version) check then had an undefined result, so http->close could remain 0 even though it should have become 1; fortunately, it was then set to 1 anyway, because there was no Content-Length header. The undefined version was also saved in http->recv_version, but it appears nothing ever reads that. So in the end, the bug did not cause any symptoms at runtime, but the warning broke the build on gcc-4.3 if ELinks was configured with --enable-debug. --- src/protocol/http/http.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/protocol/http/http.c b/src/protocol/http/http.c index e0887a098..10ab31da2 100644 --- a/src/protocol/http/http.c +++ b/src/protocol/http/http.c @@ -1453,7 +1453,7 @@ http_got_header(struct socket *socket, struct read_buffer *rb) #endif unsigned char *d; struct uri *uri = conn->proxied_uri; /* Set to the real uri */ - struct http_version version; + struct http_version version = { 0, 9 }; enum connection_state state = (conn->state != S_PROC ? S_GETH : S_PROC); int a, h = 200; int cf; @@ -1482,6 +1482,9 @@ again: read_from_socket(conn->socket, rb, state, http_got_header); return; } + /* a == -2 from get_header means HTTP/0.9. In that case, skip + * the get_http_code call; @h and @version have already been + * initialized with the right values. */ if (a == -2) a = 0; if ((a && get_http_code(rb, &h, &version)) || h == 101) {