D3698: chg: fix an undefined behavior about memcpy

quark (Jun Wu) phabricator at mercurial-scm.org
Wed Jun 6 16:03:34 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG3c84493556db: chg: fix an undefined behavior about memcpy (authored by quark, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3698?vs=8989&id=8990

REVISION DETAIL
  https://phab.mercurial-scm.org/D3698

AFFECTED FILES
  contrib/chg/chg.c

CHANGE DETAILS

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -220,7 +220,10 @@
 
 	const char **argv = mallocx(sizeof(char *) * argsize);
 	memcpy(argv, baseargv, sizeof(baseargv));
-	memcpy(argv + baseargvsize, opts->args, sizeof(char *) * opts->argsize);
+	if (opts->args) {
+		size_t size = sizeof(char *) * opts->argsize;
+		memcpy(argv + baseargvsize, opts->args, size);
+	}
 	argv[argsize - 1] = NULL;
 
 	if (putenv("CHGINTERNALMARK=") != 0)



To: quark, #hg-reviewers
Cc: durin42, mercurial-devel


More information about the Mercurial-devel mailing list