From: Johannes Schindelin Date: Tue, 08 Aug 2006 22:36:35 GMT Subject: [PATCH] mv: strcat -> strcpy to account for uninitialized memory Message-ID: In-Reply-To: <17624.55600.423000.61479@lapjr.intranet.kiel.bmiag.de> At one stage, the code assumed erroneously that the memory was initialized to zero. Signed-off-by: Johannes Schindelin --- On Tue, 8 Aug 2006, Juergen Ruehle wrote: > This might have been fixed already (my tree is a couple of days old), > but the strcat fails for me, because the alloced memory is not > cleared. > > Johannes Schindelin writes: > > +static const char *add_slash(const char *path) > > +{ > > + int len = strlen(path); > > + if (path[len - 1] != '/') { > > + char *with_slash = xmalloc(len + 2); > > + memcpy(with_slash, path, len); > > + strcat(with_slash + len, "/"); Oops. That strcat should be a strcpy, obviously. builtin-mv.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/builtin-mv.c b/builtin-mv.c index e47942c..5f57870 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -48,7 +48,7 @@ static const char *add_slash(const char if (path[len - 1] != '/') { char *with_slash = xmalloc(len + 2); memcpy(with_slash, path, len); - strcat(with_slash + len, "/"); + strcpy(with_slash + len, "/"); return with_slash; } return path; -- 1.4.2.rc3.g6b27-dirty