Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Enforce that version is a string to prevent exceptions in the case of an all-integer version ID#119

Closed
asaba96 wants to merge 4 commits intovcstools:masterfrom
asaba96:master
Closed

Enforce that version is a string to prevent exceptions in the case of an all-integer version ID#119
asaba96 wants to merge 4 commits intovcstools:masterfrom
asaba96:master

Conversation

@asaba96
Copy link
Copy Markdown

@asaba96 asaba96 commented Feb 10, 2018

If, in your workspace, you specify a specific version and the version id happens to contain all numbers, yaml.load(stream) will return the value as an integer in the resulting dictionary (see here).

This is an issue when you are using the wstool info command, as its InfoRetriever class attempts to build a path spec. However, the get_versioned_path_spec (here) calls revision = self._get_vcsc().get_version(self.version) on line 416, which is in the vcstools package. This function (here) uses the vcstools utility sanitize on line 415, which is expecting the input to be a string (see line 198 here).

However, since the PyYaml (version 3.12 on my system, Ubuntu-Gnome) returns the version as an integer, this results in an exception. The stack trace is as follows:

Traceback (most recent call last):
 File “/usr/lib/python2.7/dist-packages/wstool/common.py”, line 283, in run
   result_dict = self.worker.do_work()
 File “/usr/lib/python2.7/dist-packages/wstool/multiproject_cmd.py”, line 495, in do_work
   path_spec = self.element.get_versioned_path_spec(fetch=fetch)
 File “/usr/lib/python2.7/dist-packages/wstool/config_elements.py”, line 416, in get_versioned_path_spec
   revision = self._get_vcsc().get_version(self.version)
 File “/usr/lib/python2.7/dist-packages/vcstools/git.py”, line 415, in get_version
   command += ” %s” % sanitized(spec)
 File “/usr/lib/python2.7/dist-packages/vcstools/common.py”, line 198, in sanitized
   if arg is None or arg.strip() == ‘’:
AttributeError: ‘int’ object has no attribute ‘strip’
ERROR in config: Error processing ‘mpl_ros’ : ‘int’ object has no attribute ‘strip’

My fix enforces that the version is returned as the expected type, a string.

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 10, 2018

Coverage Status

Coverage increased (+0.009%) to 82.001% when pulling 9c44843 on asaba96:master into 3a6a2d3 on vcstools:master.

@tkruse
Copy link
Copy Markdown
Contributor

tkruse commented Feb 13, 2018

lgtm

wrap = get_path_spec_from_yaml(struct)
self.assertEqual(scmtype, wrap.get_scmtype())
self.assertEqual(scmtype, wrap.get_legacy_type())
self.assertTrue(isinstance(wrap.get_version(), str))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider using assertIsInstance here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if value is not None:
version = str(value)
else:
version = value
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the else branch needed: Version is already None?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

elif key == "version":
version = value
if value is not None:
version = str(value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, you could add str(arg).strip in the place the exception happened in vcstools, which should not be vulnerable to this. Possibly check other places we use strip without being careful about the type.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I addressed the issue here because it seemed to be caused due to the underlying PyYaml versions having different behavior in the way it returned a specific yawl value. So I could fix all exceptions related to strip or I could enforce that version is a string, which already something something above the file parsing layer already expected, so I assume there are other parts that depend on the same expectation of type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, here is a good place for a fix. vcstools is a library in it's own right (potentially to be used by other projects), so if you have time, you could also make it less vulnerable, but it's a different story from this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I will take a look then to see what I can do with vcstools when I get a chance.

@asaba96
Copy link
Copy Markdown
Author

asaba96 commented Oct 14, 2018

Is there anything else I should address for this particular PR?

@dirk-thomas
Copy link
Copy Markdown
Contributor

Closing since the repository is about to be archived: see #154.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants