west config does not sanitize option key
desowin opened this issue · 3 comments
desowin commented
The expected use case works correctly, i.e.:
[tmon@tmon-laptop ~]$ west config --global build.board
nrf52840dk_nrf52840
However, when the option does not contain period, west terminates with an unhandled exception.
[tmon@tmon-laptop ~]$ west config --global board
Traceback (most recent call last):
File "/usr/bin/west", line 33, in <module>
sys.exit(load_entry_point('west==0.14.0', 'console_scripts', 'west')())
File "/usr/lib/python3.10/site-packages/west/app/main.py", line 793, in main
app.run(argv or sys.argv[1:])
File "/usr/lib/python3.10/site-packages/west/app/main.py", line 109, in run
self.run_command(argv)
File "/usr/lib/python3.10/site-packages/west/app/main.py", line 342, in run_command
cmd.run(args, unknown, self.topdir, manifest=self.manifest,
File "/usr/lib/python3.10/site-packages/west/commands.py", line 135, in run
self.do_run(args, unknown)
File "/usr/lib/python3.10/site-packages/west/app/config.py", line 150, in do_run
self.read(args)
File "/usr/lib/python3.10/site-packages/west/app/config.py", line 181, in read
value = self.config.get(args.name, configfile=args.configfile or ALL)
File "/usr/lib/python3.10/site-packages/west/configuration.py", line 173, in get
return self._get(lambda cf: cf.get(option), default, configfile)
File "/usr/lib/python3.10/site-packages/west/configuration.py", line 216, in _get
return getter(cf)
File "/usr/lib/python3.10/site-packages/west/configuration.py", line 173, in <lambda>
return self._get(lambda cf: cf.get(option), default, configfile)
File "/usr/lib/python3.10/site-packages/west/configuration.py", line 77, in get
return self._get(option, self.cp.get)
File "/usr/lib/python3.10/site-packages/west/configuration.py", line 89, in _get
section, key = option.split('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)
It would be better to display some actual error message similar to what git config
does:
[tmon@tmon-laptop ~]$ git config --global email
error: key does not contain a section: email
marc-hb commented
I cannot reproduce, which west
version is this?
desowin commented
I cannot reproduce, which
west
version is this?
0.14.0
I tried it on clean setup, and it turns out that in order to reproduce you have to have ~/.westconfig
with at least one entry. The config can be created with e.g. west config --global build.board nrf52840dk_nrf52840
.