Merge branch 'jk/maint-http-half-auth-push' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 17 Oct 2012 17:29:24 +0000 (10:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Oct 2012 17:29:24 +0000 (10:29 -0700)
* jk/maint-http-half-auth-push:
http: fix segfault in handle_curl_result

1  2 
http.c
remote-curl.c
diff --combined http.c
index 345c171c5fd572e65e34ea421a334141a5438979,9334386d194c5519c43889f261bf35e2efaea7f5..df9bb710863e30ba98d7661f84e872b30ed4449e
--- 1/http.c
--- 2/http.c
+++ b/http.c
@@@ -4,7 -4,6 +4,7 @@@
  #include "run-command.h"
  #include "url.h"
  #include "credential.h"
 +#include "version.h"
  
  int active_requests;
  int http_is_verbose;
@@@ -300,7 -299,7 +300,7 @@@ static CURL *get_curl_handle(void
                curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
  
        curl_easy_setopt(result, CURLOPT_USERAGENT,
 -              user_agent ? user_agent : GIT_HTTP_USER_AGENT);
 +              user_agent ? user_agent : git_user_agent());
  
        if (curl_ftp_no_epsv)
                curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@@ -745,10 -744,9 +745,9 @@@ char *get_remote_object_url(const char 
        return strbuf_detach(&buf, NULL);
  }
  
- int handle_curl_result(struct active_request_slot *slot)
+ int handle_curl_result(struct active_request_slot *slot,
+                      struct slot_results *results)
  {
-       struct slot_results *results = slot->results;
        if (results->curl_result == CURLE_OK) {
                credential_approve(&http_auth);
                return HTTP_OK;
                        return HTTP_REAUTH;
                }
        } else {
 +#if LIBCURL_VERSION_NUM >= 0x070c00
                if (!curl_errorstr[0])
                        strlcpy(curl_errorstr,
                                curl_easy_strerror(results->curl_result),
                                sizeof(curl_errorstr));
 +#endif
                return HTTP_ERROR;
        }
  }
@@@ -818,11 -814,10 +817,11 @@@ static int http_request(const char *url
  
        curl_easy_setopt(slot->curl, CURLOPT_URL, url);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
 +      curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
  
        if (start_active_slot(slot)) {
                run_active_slot(slot);
-               ret = handle_curl_result(slot);
+               ret = handle_curl_result(slot, &results);
        } else {
                error("Unable to start HTTP request for %s", url);
                ret = HTTP_START_FAILED;
@@@ -926,7 -921,7 +925,7 @@@ static char *fetch_pack_index(unsigned 
        tmp = strbuf_detach(&buf, NULL);
  
        if (http_get_file(url, tmp, 0) != HTTP_OK) {
 -              error("Unable to get pack index %s\n", url);
 +              error("Unable to get pack index %s", url);
                free(tmp);
                tmp = NULL;
        }
diff --combined remote-curl.c
index a2696082fb8881d74de7a2f9c473fb03f82d81ec,6054e47929f0ecc2a2a2465d7ee3413a3842f755..468ccef58afbe273bc23bef88b1dfe527989637a
@@@ -95,7 -95,7 +95,7 @@@ static struct discovery* discover_refs(
        struct strbuf buffer = STRBUF_INIT;
        struct discovery *last = last_discovery;
        char *refs_url;
 -      int http_ret, is_http = 0, proto_git_candidate = 1;
 +      int http_ret, is_http = 0;
  
        if (last && !strcmp(service, last->service))
                return last;
        refs_url = strbuf_detach(&buffer, NULL);
  
        http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
 -
 -      /* try again with "plain" url (no ? or & appended) */
 -      if (http_ret != HTTP_OK && http_ret != HTTP_NOAUTH) {
 -              free(refs_url);
 -              strbuf_reset(&buffer);
 -
 -              proto_git_candidate = 0;
 -              strbuf_addf(&buffer, "%sinfo/refs", url);
 -              refs_url = strbuf_detach(&buffer, NULL);
 -
 -              http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
 -      }
 -
        switch (http_ret) {
        case HTTP_OK:
                break;
        last->buf_alloc = strbuf_detach(&buffer, &last->len);
        last->buf = last->buf_alloc;
  
 -      if (is_http && proto_git_candidate
 -              && 5 <= last->len && last->buf[4] == '#') {
 +      if (is_http && 5 <= last->len && last->buf[4] == '#') {
                /* smart HTTP response; validate that the service
                 * pkt-line matches our request.
                 */
@@@ -355,7 -369,7 +355,7 @@@ static int run_slot(struct active_reque
        slot->curl_result = curl_easy_perform(slot->curl);
        finish_active_slot(slot);
  
-       err = handle_curl_result(slot);
+       err = handle_curl_result(slot, &results);
        if (err != HTTP_OK && err != HTTP_REAUTH) {
                error("RPC failed; result=%d, HTTP code = %ld",
                      results.curl_result, results.http_code);
@@@ -379,7 -393,7 +379,7 @@@ static int probe_rpc(struct rpc_state *
        curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
        curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
        curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
 -      curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
 +      curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
        curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
        curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
@@@ -435,7 -449,7 +435,7 @@@ static int post_rpc(struct rpc_state *r
        curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
        curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
        curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
 -      curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
 +      curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
  
        headers = curl_slist_append(headers, rpc->hdr_content_type);
        headers = curl_slist_append(headers, rpc->hdr_accept);