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

Validate I/O in case addons pass incorrect values #2720

Merged
merged 4 commits into from
Aug 12, 2023

Conversation

Vurv78
Copy link
Contributor

@Vurv78 Vurv78 commented Aug 10, 2023

This applies to wiremod as a whole, now inputs and outputs will be validated to ensure correctness on TriggerInput/TriggerOutput (E2 wirelinks use this as well).

In this case the value will be replaced with the default value for the type.

@Vurv78 Vurv78 requested a review from thegrb93 August 10, 2023 03:08
local ty = WireLib.DT[output.Type]
if ty and not ty.Validator(value) then
-- Not copying here is fine since data types are immutable outside E2.
value = ty.Zero
Copy link
Contributor

Choose a reason for hiding this comment

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

Should return a copy of 'Zero'. Maybe change 'ty.Zero' into a function that returns a new zero so this line becomes value = ty.Zero()

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how ports handle mutable types, so maybe I'm wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wire just doesn't mutate any data types, and E2 table.Copys the types before using them and outputting them.

But since this is a PR to fix addon creators potentially messing stuff up, might as well do this too in case they mutate the default value.

@thegrb93
Copy link
Contributor

Um, one other issue is this is going to fuck performance in x64 gmod. Facepunch/garrysmod-issues#4100

@Vurv78
Copy link
Contributor Author

Vurv78 commented Aug 11, 2023

I mean, this is serverside, I doubt many servers are hosted on 64 bit

@thegrb93
Copy link
Contributor

Yeah

@Vurv78 Vurv78 merged commit b170fce into wiremod:master Aug 12, 2023
1 check passed
@Vurv78 Vurv78 deleted the validate-io branch August 12, 2023 20:58
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.

2 participants