* [PATCH] daemon: plug memory leak on overlong path
@ 2021-12-18 9:47 René Scharfe
2021-12-18 10:18 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2021-12-18 9:47 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano, Jeff King
Release the strbuf containing the interpolated path after copying it to
a stack buffer and before erroring out if it's too long.
Signed-off-by: René Scharfe <l.s.r@web.de>
---
daemon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon.c b/daemon.c
index 4a000ee4af..94a5b8a364 100644
--- a/daemon.c
+++ b/daemon.c
@@ -232,13 +232,13 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
rlen = strlcpy(interp_path, expanded_path.buf,
sizeof(interp_path));
+ strbuf_release(&expanded_path);
if (rlen >= sizeof(interp_path)) {
logerror("interpolated path too large: %s",
interp_path);
return NULL;
}
- strbuf_release(&expanded_path);
loginfo("Interpolated dir '%s'", interp_path);
dir = interp_path;
--
2.34.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] daemon: plug memory leak on overlong path
2021-12-18 9:47 [PATCH] daemon: plug memory leak on overlong path René Scharfe
@ 2021-12-18 10:18 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2021-12-18 10:18 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
On Sat, Dec 18, 2021 at 10:47:03AM +0100, René Scharfe wrote:
> Release the strbuf containing the interpolated path after copying it to
> a stack buffer and before erroring out if it's too long.
Thanks, this looks obviously correct. The problem was introduced by my
6bdb0083be (daemon: detect and reject too-long paths, 2016-10-22).
I don't think it's that big a deal in practice, since we'd always be in
a worker process handling a single request, and will exit immediately
after returning from the function. So you could not, say, convince a
long-running git-daemon to leak a bunch of memory over time.
But definitely still worth fixing.
> diff --git a/daemon.c b/daemon.c
> index 4a000ee4af..94a5b8a364 100644
> --- a/daemon.c
> +++ b/daemon.c
> @@ -232,13 +232,13 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
>
> rlen = strlcpy(interp_path, expanded_path.buf,
> sizeof(interp_path));
> + strbuf_release(&expanded_path);
> if (rlen >= sizeof(interp_path)) {
> logerror("interpolated path too large: %s",
> interp_path);
> return NULL;
> }
>
> - strbuf_release(&expanded_path);
> loginfo("Interpolated dir '%s'", interp_path);
A common mistake in these kinds of fixes is that the variable to be
freed is used to generate an error message in the early-return path.
Here we put "interp_path" in the message instead. That does mean the
error message shows the truncated name rather than the full one. That
may be a hidden feature, though. :)
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-18 10:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-18 9:47 [PATCH] daemon: plug memory leak on overlong path René Scharfe
2021-12-18 10:18 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox