Skip to contentSkip to conversation

builtin-push: don't access freed transport->url

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 builtin-push: don't access freed transport->url

Move the failed push message to before transport_disconnect() so that it doesn't access transport->url after transport has been free()'d (in transport_disconnect()).

Additionally, make the failed push message more accurate by moving it before transport_disconnect(), so that it doesn't report errors due to a failed disconnect.

Cc "Daniel Barkalow" <[email protected]>
---
 builtin-push.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
builtin-push.c +3 -2
index a21e46c..dcfb53f 100644
@@ -101,13 +101,14 @@ static int push_with_options(struct transport *transport, int flags)
 		fprintf(stderr, "Pushing to %s\n", transport->url);
 	err = transport_push(transport, refspec_nr, refspec, flags,
 			     &nonfastforward);
+	if (err != 0)
+		error("failed to push some refs to '%s'", transport->url);
+
 	err |= transport_disconnect(transport);
 
 	if (!err)
 		return 0;
 
-	error("failed to push some refs to '%s'", transport->url);
-
 	if (nonfastforward && advice_push_nonfastforward) {
 		printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
 		       "Merge the remote changes before pushing again.  See the 'non-fast-forward'\n"

--
1.6.6.rc1.249.g048b3

Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Tay Ray Chuan

Move the failed push message to before transport_disconnect() so that it doesn't access transport->url after transport has been free()'d (in transport_disconnect()).

Additionally, make the failed push message more accurate by moving it before transport_disconnect(), so that it doesn't report errors due to a failed disconnect.

Cc "Daniel Barkalow" <[email protected]>
Quoted 28 lines
---
 builtin-push.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
builtin-push.c +3 -3
index a21e46c..dcfb53f 100644
@@ -101,13 +101,14 @@ static int push_with_options(struct transport *transport, int flags)
 		fprintf(stderr, "Pushing to %s\n", transport->url);
 	err = transport_push(transport, refspec_nr, refspec, flags,
 			     &nonfastforward);
+	if (err != 0)
+		error("failed to push some refs to '%s'", transport->url);
+
 	err |= transport_disconnect(transport);
 
 	if (!err)
 		return 0;
 
-	error("failed to push some refs to '%s'", transport->url);
-
 	if (nonfastforward && advice_push_nonfastforward) {
 		printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
 		       "Merge the remote changes before pushing again.  See the 'non-fast-forward'\n"
--

1.6.6.rc1.249.g048b3

#2 lore raw

Thanks, both; queued at the top of sr/vcs-helpers topic and merged to 'next'.