diff options
author | Mike Frysinger <vapier@google.com> | 2021-02-25 21:53:49 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-02-28 16:07:12 +0000 |
commit | a29424ea6d6f5a38ef9c25141c9f095161dbd3ff (patch) | |
tree | 0f8772476b727db41976ca70169de854cc67dbfd /manifest_xml.py | |
parent | a00c5f40e76fd520597013ae89823711212630b3 (diff) | |
download | git-repo-a29424ea6d6f5a38ef9c25141c9f095161dbd3ff.tar.gz |
manifest: validate project name & path and include name attributes
These attribute values are used to construct local filesystem paths,
so apply the existing filesystem checks to them.
Bug: https://crbug.com/gerrit/14156
Change-Id: Ibcceecd60fa74f0eb97cd9ed1a9792e139534ed4
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/298443
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'manifest_xml.py')
-rw-r--r-- | manifest_xml.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index d05f4d0a..cd5954df 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -670,6 +670,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
670 | for node in manifest.childNodes: | 670 | for node in manifest.childNodes: |
671 | if node.nodeName == 'include': | 671 | if node.nodeName == 'include': |
672 | name = self._reqatt(node, 'name') | 672 | name = self._reqatt(node, 'name') |
673 | msg = self._CheckLocalPath(name) | ||
674 | if msg: | ||
675 | raise ManifestInvalidPathError( | ||
676 | '<include> invalid "name": %s: %s' % (name, msg)) | ||
673 | include_groups = '' | 677 | include_groups = '' |
674 | if parent_groups: | 678 | if parent_groups: |
675 | include_groups = parent_groups | 679 | include_groups = parent_groups |
@@ -979,6 +983,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
979 | reads a <project> element from the manifest file | 983 | reads a <project> element from the manifest file |
980 | """ | 984 | """ |
981 | name = self._reqatt(node, 'name') | 985 | name = self._reqatt(node, 'name') |
986 | msg = self._CheckLocalPath(name, dir_ok=True) | ||
987 | if msg: | ||
988 | raise ManifestInvalidPathError( | ||
989 | '<project> invalid "name": %s: %s' % (name, msg)) | ||
982 | if parent: | 990 | if parent: |
983 | name = self._JoinName(parent.name, name) | 991 | name = self._JoinName(parent.name, name) |
984 | 992 | ||
@@ -999,9 +1007,11 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
999 | path = node.getAttribute('path') | 1007 | path = node.getAttribute('path') |
1000 | if not path: | 1008 | if not path: |
1001 | path = name | 1009 | path = name |
1002 | if path.startswith('/'): | 1010 | else: |
1003 | raise ManifestParseError("project %s path cannot be absolute in %s" % | 1011 | msg = self._CheckLocalPath(path, dir_ok=True) |
1004 | (name, self.manifestFile)) | 1012 | if msg: |
1013 | raise ManifestInvalidPathError( | ||
1014 | '<project> invalid "path": %s: %s' % (path, msg)) | ||
1005 | 1015 | ||
1006 | rebase = XmlBool(node, 'rebase', True) | 1016 | rebase = XmlBool(node, 'rebase', True) |
1007 | sync_c = XmlBool(node, 'sync-c', False) | 1017 | sync_c = XmlBool(node, 'sync-c', False) |
@@ -1124,7 +1134,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1124 | def _CheckLocalPath(path, dir_ok=False, cwd_dot_ok=False): | 1134 | def _CheckLocalPath(path, dir_ok=False, cwd_dot_ok=False): |
1125 | """Verify |path| is reasonable for use in filesystem paths. | 1135 | """Verify |path| is reasonable for use in filesystem paths. |
1126 | 1136 | ||
1127 | Used with <copyfile> & <linkfile> elements. | 1137 | Used with <copyfile> & <linkfile> & <project> elements. |
1128 | 1138 | ||
1129 | This only validates the |path| in isolation: it does not check against the | 1139 | This only validates the |path| in isolation: it does not check against the |
1130 | current filesystem state. Thus it is suitable as a first-past in a parser. | 1140 | current filesystem state. Thus it is suitable as a first-past in a parser. |