@matheusbsbs / matheus-bagliano / commits / 16493eb0d0
Fork 0

http*: cleanup slot->local after fclose

Set slot->local to NULL after doing a fclose() on the file it points to. This prevents the passing of a FILE* pointer to a fclose()'d file to ftell() in http.c::run_active_slot(). This issue was raised by Clemens Buchacher on 30th May 2009: http://www.spinics.net/lists/git/msg104623.html Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Jun 6, 2009 at 16:43 UTC 16493eb0d0da26f80286b39c7b6900e261744afa
2 files changed +12
http-push.c
+6
@@ -724,9 +724,11 @@ static void finish_request(struct transfer_request *request)
724 struct stat st;
725 struct packed_git *target;
726 struct packed_git **lst;
727 + struct active_request_slot *slot;
728
729 request->curl_result = request->slot->curl_result;
730 request->http_code = request->slot->http_code;
731 + slot = request->slot;
732 request->slot = NULL;
733
734 /* Keep locks active */
@@ -823,6 +825,7 @@ static void finish_request(struct transfer_request *request)
825
826 fclose(request->local_stream);
827 request->local_stream = NULL;
828 + slot->local = NULL;
829 if (!move_temp_to_file(request->tmpfile,
830 request->filename)) {
831 target = (struct packed_git *)request->userData;
@@ -1024,17 +1027,20 @@ static int fetch_index(unsigned char *sha1)
1027 if (results.curl_result != CURLE_OK) {
1028 free(url);
1029 fclose(indexfile);
1030 + slot->local = NULL;
1031 return error("Unable to get pack index %s\n%s", url,
1032 curl_errorstr);
1033 }
1034 } else {
1035 free(url);
1036 fclose(indexfile);
1037 + slot->local = NULL;
1038 return error("Unable to start request");
1039 }
1040
1041 free(url);
1042 fclose(indexfile);
1043 + slot->local = NULL;
1044
1045 return move_temp_to_file(tmpfile, filename);
1046 }
http-walker.c
+6
@@ -418,15 +418,18 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
418 run_active_slot(slot);
419 if (results.curl_result != CURLE_OK) {
420 fclose(indexfile);
421 + slot->local = NULL;
422 return error("Unable to get pack index %s\n%s", url,
423 curl_errorstr);
424 }
425 } else {
426 fclose(indexfile);
427 + slot->local = NULL;
428 return error("Unable to start request");
429 }
430
431 fclose(indexfile);
432 + slot->local = NULL;
433
434 return move_temp_to_file(tmpfile, filename);
435 }
@@ -776,16 +779,19 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
779 run_active_slot(slot);
780 if (results.curl_result != CURLE_OK) {
781 fclose(packfile);
782 + slot->local = NULL;
783 return error("Unable to get pack file %s\n%s", url,
784 curl_errorstr);
785 }
786 } else {
787 fclose(packfile);
788 + slot->local = NULL;
789 return error("Unable to start request");
790 }
791
792 target->pack_size = ftell(packfile);
793 fclose(packfile);
794 + slot->local = NULL;
795
796 ret = move_temp_to_file(tmpfile, filename);
797 if (ret)