Skip to contentSkip to conversation

http*: cleanup slot->local after fclose

PATCH In review Tay Ray Chuan 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 3/23 http*: cleanup slot->local after fclose

Set slot->local to NULL after doing a fclose on the FILE* pointer it points to. This prevents an invalid FILE* pointer from being passed to ftell() in http.c::run_active_slot().

This issue was raised by Clemens Buchacher on 30th May:

http://www.spinics.net/lists/git/msg104623.html

---

I've made it more clear what issue this patch is fixing.

 http-push.c   |    6 ++++++
 http-walker.c |    6 ++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
http-push.c +6 -0
index e16a0ad..0b12ffe 100644
@@ -724,9 +724,11 @@ static void finish_request(struct transfer_request *request)
 	struct stat st;
 	struct packed_git *target;
 	struct packed_git **lst;
+	struct active_request_slot *slot;
 
 	request->curl_result = request->slot->curl_result;
 	request->http_code = request->slot->http_code;
+	slot = request->slot;
 	request->slot = NULL;
 
 	/* Keep locks active */
@@ -823,6 +825,7 @@ static void finish_request(struct transfer_request *request)
 
 			fclose(request->local_stream);
 			request->local_stream = NULL;
+			slot->local = NULL;
 			if (!move_temp_to_file(request->tmpfile,
 					       request->filename)) {
 				target = (struct packed_git *)request->userData;
@@ -1024,17 +1027,20 @@ static int fetch_index(unsigned char *sha1)
 		if (results.curl_result != CURLE_OK) {
 			free(url);
 			fclose(indexfile);
+			slot->local = NULL;
 			return error("Unable to get pack index %s\n%s", url,
 				     curl_errorstr);
 		}
 	} else {
 		free(url);
 		fclose(indexfile);
+		slot->local = NULL;
 		return error("Unable to start request");
 	}
 
 	free(url);
 	fclose(indexfile);
+	slot->local = NULL;
 
 	return move_temp_to_file(tmpfile, filename);
 }
http-walker.c +6 -0
index 7321ccc..9377851 100644
@@ -418,15 +418,18 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
 		run_active_slot(slot);
 		if (results.curl_result != CURLE_OK) {
 			fclose(indexfile);
+			slot->local = NULL;
 			return error("Unable to get pack index %s\n%s", url,
 				     curl_errorstr);
 		}
 	} else {
 		fclose(indexfile);
+		slot->local = NULL;
 		return error("Unable to start request");
 	}
 
 	fclose(indexfile);
+	slot->local = NULL;
 
 	return move_temp_to_file(tmpfile, filename);
 }
@@ -776,16 +779,19 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
 		run_active_slot(slot);
 		if (results.curl_result != CURLE_OK) {
 			fclose(packfile);
+			slot->local = NULL;
 			return error("Unable to get pack file %s\n%s", url,
 				     curl_errorstr);
 		}
 	} else {
 		fclose(packfile);
+		slot->local = NULL;
 		return error("Unable to start request");
 	}
 
 	target->pack_size = ftell(packfile);
 	fclose(packfile);
+	slot->local = NULL;
 
 	ret = move_temp_to_file(tmpfile, filename);
 	if (ret)

--
1.6.3.1

#1 lore raw
Quoted 3 lines · Tay Ray Chuan

Set slot->local to NULL after doing a fclose on the FILE* pointer it points to. This prevents an invalid FILE* pointer from being passed to ftell() in http.c::run_active_slot().

You mean here passing FILE* pointer to a fclosed file to ftell()?

Quoted 2 lines

This issue was raised by Clemens Buchacher on 30th May:

Just in case: 30th May 2009?

Quoted 4 lines

http://www.spinics.net/lists/git/msg104623.html

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#2 lore raw

Hi,

Quoted 1 line · Jakub Narebski

You mean here passing FILE* pointer to a fclosed file to ftell()?

Ok.

Quoted 1 line

Just in case: 30th May 2009?

Yes.

Signature · 2 lines
Cheers,
Ray Chuan