diff options
author | Tom Cherry <tomcherry@google.com> | 2018-02-08 14:26:53 -0800 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2018-02-09 18:46:13 +0000 |
commit | ee0610e86cc947d61ff137d242c8ab045b267854 (patch) | |
tree | 441e37b7e23116ac7a9326fc077c744e74a93081 /tools/fs_config | |
parent | 74413198b736f7c4e4698546b5763907ed4e1643 (diff) | |
download | platform_build-ee0610e86cc947d61ff137d242c8ab045b267854.tar.gz platform_build-ee0610e86cc947d61ff137d242c8ab045b267854.tar.bz2 platform_build-ee0610e86cc947d61ff137d242c8ab045b267854.zip |
Add compile time check that friendly AID names are < 32 characters
There is an internal buffer in bionic for user/group names that is 32
characters long including the trailing null, so we must restrict the
length of these names during compile time.
Bug: 27999086
Test: Successfully compile a valid config.fs
Test: Fail to compile a config.fs with AID name > 31 characters
Change-Id: I7fe887c630dd4d1033b86a5d8332480eb3b0fa07
Diffstat (limited to 'tools/fs_config')
-rwxr-xr-x | tools/fs_config/fs_config_generator.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/fs_config/fs_config_generator.py b/tools/fs_config/fs_config_generator.py index c8d1dd33a1..d51d075e0d 100755 --- a/tools/fs_config/fs_config_generator.py +++ b/tools/fs_config/fs_config_generator.py @@ -146,18 +146,27 @@ class AID(object): found (str): The file found in, not required to be specified. Raises: + ValueError: if the friendly name is longer than 31 characters as + that is bionic's internal buffer size for name. ValueError: if value is not a valid string number as processed by int(x, 0) """ self.identifier = identifier self.value = value self.found = found - self.normalized_value = str(int(value, 0)) + try: + self.normalized_value = str(int(value, 0)) + except ValueException: + raise ValueError('Invalid "value", not aid number, got: \"%s\"' % value) # Where we calculate the friendly name friendly = identifier[len(AID.PREFIX):].lower() self.friendly = AID._fixup_friendly(friendly) + if len(self.friendly) > 31: + raise ValueError('AID names must be under 32 characters "%s"' % self.friendly) + + def __eq__(self, other): return self.identifier == other.identifier \ @@ -639,10 +648,8 @@ class FSConfigFileParser(object): try: aid = AID(section_name, value, file_name) - except ValueError: - sys.exit( - error_message('Invalid "value", not aid number, got: \"%s\"' % - value)) + except ValueError as exception: + sys.exit(error_message(exception)) # Values must be within OEM range if not Utils.in_any_range(int(aid.value, 0), self._oem_ranges): |