* [PATCH] fetch-pack: Avoid memcpy() with src==dst
@ 2008-12-06 20:50 Thomas Rast
2008-12-08 2:47 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Rast @ 2008-12-06 20:50 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
memcpy() may only be used for disjoint memory areas, but when invoked
from cmd_fetch_pack(), we have my_args == &args. (The argument cannot
be removed entirely because transport.c invokes with its own
variable.)
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Found this while valgrinding too much.
builtin-fetch-pack.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 372bfa2..67fb80e 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -780,7 +780,8 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
struct ref *ref_cpy;
fetch_pack_setup();
- memcpy(&args, my_args, sizeof(args));
+ if (&args != my_args)
+ memcpy(&args, my_args, sizeof(args));
if (args.depth > 0) {
if (stat(git_path("shallow"), &st))
st.st_mtime = 0;
--
tg: (7f705dc..) t/fp-memcpy-fix (depends on: origin/master)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fetch-pack: Avoid memcpy() with src==dst
2008-12-06 20:50 [PATCH] fetch-pack: Avoid memcpy() with src==dst Thomas Rast
@ 2008-12-08 2:47 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-12-08 2:47 UTC (permalink / raw)
To: Thomas Rast; +Cc: git
Thomas Rast <trast@student.ethz.ch> writes:
> memcpy() may only be used for disjoint memory areas, but when invoked
> from cmd_fetch_pack(), we have my_args == &args. (The argument cannot
> be removed entirely because transport.c invokes with its own
> variable.)
It makes me wonder if it might be a better fix to abolish the use of file
scoped global "args" and pass a pointer to "struct fetch_pack_args"
throughout the callchain instead.
In the current code, cmd_fetch_pack() is the only caller that passes &args
to this function, but it is not so implausible to have a future callchain
that makes two calls to cmd_fetch_pack(), perhaps implementing some sort
of alias to fetch from multiple places, would horribly break without such
a fix, because cmd_fetch_pack() assumes that args is in its pristine
state.
I'll apply this to 'maint' and merge it up, because the patch is
independent of the above issue.
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-12-08 2:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-06 20:50 [PATCH] fetch-pack: Avoid memcpy() with src==dst Thomas Rast
2008-12-08 2:47 ` Junio C Hamano
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 NNTP newsgroup(s).