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

Engine.SetValue with null strings crashes with NullReferenceException since 3.0.0-beta-2045 #1486

Closed
christianrondeau opened this issue Mar 10, 2023 · 3 comments · Fixed by #1490

Comments

@christianrondeau
Copy link
Contributor

Problem:

For example, this code:

var engine = new Engine();
engine.SetValue("x", (string)null);

will throw, because SetValue calls JsString.Create directly which doesn't make null checks.

Fix:

I see two potential fixes for that:

  1. Make JsString.Create return a JsValue that could either be Null or the JsString, this would always work but may be troublesome
  2. Simply add an if statement in Engine.SetValue(string, string) to either set a JsString or null. This is safer but other places may also be affected that I didn't notice.

Since:

3.0.0-beta-2045 (commit 6839807)

In any case the fix is dead simple, I just want to make sure I'm not missing something this change did intentionally.

@lahma
Copy link
Collaborator

lahma commented Mar 10, 2023

I guess nullable annotations were expected to be respected to cover this, but of course consuming code can force anything in.

The second option seems reasonable. First option can affect performance and cause changes to be required on callsites.

@christianrondeau
Copy link
Contributor Author

All right, I'll do that (maybe today). We have Nullable enabled almost everywhere ;)

@christianrondeau
Copy link
Contributor Author

That was fast, thanks <3

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 a pull request may close this issue.

2 participants