Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect invalid license expressions containing () #879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bwoodsend
Copy link

The following condensed list of expressions are all currently mislabelled as valid by canonicalize_license_expression().

( ) or MIT
MIT and ( )
( ) and MIT or MIT
( ) with ( MIT )
( ) with ( ) or MIT
MIT with ( ) with ( ) or MIT

The trick of converting license expressions to Python statements runs afoul of () being an empty tuple (i.e. valid syntax and falsy). Depending on how () is combined with real Falses, it may or may not get caught by the subsequent eval(python_expression) is False check:

MIT or ()  ->  False or ()  ->  ()     # Caught
() or MIT  ->  () or False  ->  False  # Not caught

Consider a license expression invalid if a ) comes immediately after a ( token. This also removes the one case where the eval() would return something other than False so that eval() can now be downgraded to a compile() (which I find very anxiety relieving even though I can't think of any way the old eval() could ever have been exposed to more than Falses or ()s).

The following condensed list of expressions are all currently
mislabelled as valid by `canonicalize_license_expression()`.

    ( ) or MIT
    MIT and ( )
    ( ) and MIT or MIT
    ( ) with ( MIT )
    ( ) with ( ) or MIT
    MIT with ( ) with ( ) or MIT

The trick of converting license expressions to Python statements runs
afoul of `()` being an empty tuple (i.e. valid syntax and falsy).
Depending on how `()` is combined with real `False`s, it may or may not
get caught by the subsequent `eval(python_expression) is False` check:

    MIT or ()  ->  False or ()  ->  ()     # Caught
    () or MIT  ->  () or False  ->  False  # Not caught

Consider a license expression invalid if a `)` comes immediately after a
`(` token. This also removes the one case where the `eval()` would
return something other than `False` so that `eval()` can now be
downgraded to a `compile()` (which I find very anxiety relieving even
though I can't think of any way the old `eval()` could ever have been
exposed to more than `False`s or `()`s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant