git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] shallow.c: Don't free unallocated slabs
@ 2019-09-30 23:33 Ali Utku Selen
  2019-10-01 15:07 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Ali Utku Selen @ 2019-09-30 23:33 UTC (permalink / raw)
  To: git; +Cc: Ali Utku Selen

Fix possible segfault when cloning a submodule shallow.

Signed-off-by: Ali Utku Selen <auselen@gmail.com>
---
It is possible to have unallocated slabs in shallow.c's commit_depth
for a shallow submodule with many commits.

Easiest way to reproduce this I found was changing COMMIT_SLAB_SIZE to
32 and run t7406-submodule-update.sh. Segfault happens in case 50:
"submodule update clone shallow submodule outside of depth"

 shallow.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/shallow.c b/shallow.c
index 5fa2b15d37..c33ab94bd7 100644
--- a/shallow.c
+++ b/shallow.c
@@ -156,6 +156,8 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 	for (i = 0; i < depths.slab_count; i++) {
 		int j;
 
+		if (!depths.slab[i])
+			continue;
 		for (j = 0; j < depths.slab_size; j++)
 			free(depths.slab[i][j]);
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] shallow.c: Don't free unallocated slabs
  2019-09-30 23:33 [PATCH] shallow.c: Don't free unallocated slabs Ali Utku Selen
@ 2019-10-01 15:07 ` Jeff King
  2019-10-02  6:01   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2019-10-01 15:07 UTC (permalink / raw)
  To: Ali Utku Selen; +Cc: git

On Tue, Oct 01, 2019 at 01:33:10AM +0200, Ali Utku Selen wrote:

> Fix possible segfault when cloning a submodule shallow.

Thanks. Just looking at the context, this is clearly the right thing to
be doing.

> It is possible to have unallocated slabs in shallow.c's commit_depth
> for a shallow submodule with many commits.

Yeah, the trick here is that we may over-allocate the slab list but not
fill all of the entries. This is really an internal implementation
detail of how the slab code works. It would be nice if callers didn't
have to care about it. Perhaps we ought to have a slab foreach()
function that encapsulates this, which would let this caller do
something like:

  commit_depth_foreach(&depths, free_commit_depth);
  commit_depth_clear(&depths);

But since this is the only place that looks into the slab in this way,
I'm happy to take your much simpler fix in the meantime.

> Easiest way to reproduce this I found was changing COMMIT_SLAB_SIZE to
> 32 and run t7406-submodule-update.sh. Segfault happens in case 50:
> "submodule update clone shallow submodule outside of depth"

It would be nice to have a test, but I suspect it would be kind of
expensive, since it requires 512kb+ of entries (and would obviously be
depending on this arbitrary internal value). Given the simplicity of the
fix, I think we can live without it.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] shallow.c: Don't free unallocated slabs
  2019-10-01 15:07 ` Jeff King
@ 2019-10-02  6:01   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2019-10-02  6:01 UTC (permalink / raw)
  To: Jeff King; +Cc: Ali Utku Selen, git

Jeff King <peff@peff.net> writes:

> ... This is really an internal implementation
> detail of how the slab code works. It would be nice if callers didn't
> have to care about it. Perhaps we ought to have a slab foreach()
> function that encapsulates this, which would let this caller do
> something like:
>
>   commit_depth_foreach(&depths, free_commit_depth);
>   commit_depth_clear(&depths);
>
> But since this is the only place that looks into the slab in this way,
> I'm happy to take your much simpler fix in the meantime.

Likewise.  Thanks, both.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-02  6:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30 23:33 [PATCH] shallow.c: Don't free unallocated slabs Ali Utku Selen
2019-10-01 15:07 ` Jeff King
2019-10-02  6:01   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).