Patchwork D3698: chg: fix an undefined behavior about memcpy

login
register
mail settings
Submitter phabricator
Date June 6, 2018, 8:03 p.m.
Message ID <82bfa19a0a739a47fcf165e0cb7cae7d@localhost.localdomain>
Download mbox | patch
Permalink /patch/31994/
State Not Applicable
Headers show

Comments

phabricator - June 6, 2018, 8:03 p.m.
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




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

Patch

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)