git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] mv: strcat -> strcpy to account for uninitialized memory

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 8, 2006, 22:36 UTC
Message-ID
<Pine.LNX.4.63.0608090031390.1800@wbgn013.biozentrum.uni-wuerzburg.de>
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 <Johannes.Schindelin@gmx.de>
---
	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
Previous: Junio C Hamano
Message 5 of 5 in “builtin git-mv: support moving directories”
  1. 2/2 builtin git-mv: support moving directoriesJohannes Schindelin, Jul 26, 2006
  2. Junio C HamanoJul 26, 2006
  3. Juergen RuehleAug 8, 2006
  4. Junio C HamanoAug 8, 2006
  5. mv: strcat -> strcpy to account for uninitialized memoryJohannes Schindelin, Aug 8, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.