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

Add builtin::is_tainted #19854

Merged
merged 1 commit into from
Jul 5, 2022
Merged

Add builtin::is_tainted #19854

merged 1 commit into from
Jul 5, 2022

Conversation

JRaspass
Copy link
Contributor

I know we intend to re-revert #19541 at some point this cycle but I still think taint is useful and does have users, so with that in mind I've added builtin::taint.

It seemed like the least controversial of the taint related options to add but I would like to add taint and untaint in the future too, we just need to bikeshed whether we think they ought to handle nested structures or variadic arguments, etc.

If and when #19541 comes back in we will need to make the new tests conditional on taint support. We also should probably decide what the op should do when taint mode is disabled. Either throw or return false, ATM it'll do whatever SvTAINTED does on perls with no taint support, I think return false always.

There might be a simpler way to write the C but I couldn't come up with much, I considered adding a PUSHb macro to push a bool onto the stack but I wasn't sure if there would be enough interest in that, it could simplify other ops like pp_is_bool and pp_is_weak

t/perf/opcount.t Outdated Show resolved Hide resolved
@leonerd
Copy link
Contributor

leonerd commented Jun 12, 2022

I think this all looks good.

As you say, at some point we should bikeshed the idea of whether to also add taint and untaint. It's a bit unfortunate that we're adding these to builtin now while also contemplating adding a configuration option to remove tainting altogether; though even with that in place many people will still have taint-enabled perls for a long time yet; so we might as well add these to builtin all the same.

pp.c Outdated Show resolved Hide resolved
@JRaspass
Copy link
Contributor Author

I've simplified the code as per tonycoz's suggestion and applied the same change to other bool builtins (is_bool and is_weak).

So am I right in thinking the reason we don't need/want the target logic is that it's primarily an optimisation to avoid needing to create a new SV in the event that there's already an SV on the left, and since we're returning one of two global bools now we're not building a new SV anyways.

@Leont
Copy link
Contributor

Leont commented Jun 13, 2022

I don't think that test will pass when tainting is disabled.

@tonycoz
Copy link
Contributor

tonycoz commented Jun 14, 2022

So am I right in thinking the reason we don't need/want the target logic is that it's primarily an optimisation to avoid needing to create a new SV in the event that there's already an SV on the left, and since we're returning one of two global bools now we're not building a new SV anyways.

That's right.

I'll admit I wasn't thinking of the targlex optimization when I made that comment, but I still think it's better to optimize for the more common use in an expression or conditional for these functions rather than the rare direct assignment to a non-LVAL_INTRO lexical.

@JRaspass
Copy link
Contributor Author

I don't think that test will pass when tainting is disabled.

True, I pushed this change which seems to work for me in my local testing:

-    ok(tainted($0), "\$0 is tainted");
+    is(tainted($0), !!${^TAINT}, "\$0 is tainted (if tainting is supported)");

@xenu
Copy link
Member

xenu commented Jun 14, 2022

Adding this function would feel like an endorsement of a very controversial feature. I'm not in favour of this.

@JRaspass
Copy link
Contributor Author

So what's the plan wrt tainting. I was under the impression that we were going to turn the compiler define into a configure define in the near future (making no taint support the same level of official as no thread support). And then in the future maybe default to it off. I don't see how (or why) we could remove it without needlessly breaking people's code (including my employer's large perl codebase).

Tainting is defence in depth for people who want it, I can understand the appeal of disabling it for more performance, and even making it default to off but to remove it seems unlikely, but that's just my $.02.

Also I don't see how making a faster version of what's already in core via Scalar::Util makes it any more of an endorsement or hurts anything.

@xenu
Copy link
Member

xenu commented Jun 14, 2022

So what's the plan wrt tainting.

I don't think there's a long term plan. The only thing that was agreed on was adding a Configure flag to disable it.

My personal opinion is that it should be completely removed, but it's just me.

we could remove it without needlessly breaking people's code (including my employer's large perl codebase).

I'm curious in what way your code relies on the taint mode. What exactly (apart from tests which explicitly check for taintness) would break if taint mode disappeared and -T was a no-op?

Also I don't see how making a faster version of what's already in core via Scalar::Util makes it any more of an endorsement or hurts anything.

If we're extending some feature, in this case by adding a new builtin for it, it sends a message that this feature is fully supported and here to stay.

@Leont
Copy link
Contributor

Leont commented Jun 14, 2022

I can understand the appeal of disabling it for more performance, and even making it default to off but to remove it seems unlikely, but that's just my $.02.

Yeah, that's also my analysis.

@tonycoz
Copy link
Contributor

tonycoz commented Jul 4, 2022

There's been no discussion of completely removing taint, so I think it's reasonable to apply this.

If we were consistent on naming our boolean test functions I'd suggest renaming to is_tainted, but we haven't been consistent (is_weak, is_bool, blessed).

If you can rebase it and resolve the conflicts I'll apply it.

If we decide at some point to remove tainting this can be modified to always return false, or be removed.

@JRaspass JRaspass force-pushed the builtin-tainted branch 2 times, most recently from d3d1ce6 to 779578d Compare July 4, 2022 08:09
@haarg
Copy link
Contributor

haarg commented Jul 4, 2022

blessed doesn't return a boolean, so it doesn't use an is_ prefix. This should probably be is_tainted.

@JRaspass
Copy link
Contributor Author

JRaspass commented Jul 4, 2022

blessed doesn't return a boolean, so it doesn't use an is_ prefix. This should probably be is_tainted.

Fair, I just copied Scalar::Util, I'll rename.

Also tweak the implementation of the other two boolean builtins (is_bool
& is_weak) to be slightly more efficient.
@JRaspass
Copy link
Contributor Author

JRaspass commented Jul 4, 2022

Rebased, renamed, and squashed.

@JRaspass JRaspass changed the title Add builtin::tainted Add builtin::is_tainted Jul 4, 2022
@tonycoz tonycoz merged commit a02b815 into Perl:blead Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants