http://qs321.pair.com?node_id=11135833


in reply to Proposed change regarding "Taint" support

G'day Rob,

Thanks for advising of this proposal.

I was wondering about the taint-related overhead. I'm not an XS programmer; however, I did some investigation using Devel::Peek and followed that up with some hunting around in perlguts.

I'm genuinely interested in learning about this. My investigations are potentially incomplete and my inferences could easily be wrong. Any constructive criticism would be welcome.

Without any implicit (setuid/getuid) or explicit (-T) taint checking:

$ perl -e 'use Devel::Peek; my $x = $ENV{PATH}; Dump $x' SV = PVMG(0x8000c68f0) at 0x80008a8b8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) IV = 0 NV = 0 PV = 0x80008c2c0 "... long list of pathnames ..."\0 CUR = 2026 LEN = 2028 COW_REFCNT = 1 $ perl -e 'use Devel::Peek; my $x = q{$ENV{PATH}}; Dump $x' SV = PV(0x800004670) at 0x80008a8a8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x80008e250 "$ENV{PATH}"\0 CUR = 10 LEN = 12 COW_REFCNT = 1

So, ignoring the hex numbers — which I assumed were related to memory locations, like HASH(0x800003c88), ARRAY(0x800003cd0), etc. — and the values directly related to the string content, it would seem that the elements taking part in any overhead are SV = PVMG (cf. SV = PV) and the additional IV and NV. I wasn't able to figure out exactly what that overhead might be.

Now, I could be barking up the wrong tree, which is entirely possible, and, if so, please correct my conclusions. It seems there is no overhead unless there are tainted variables. Is there something else going on that I've overlooked or, perhaps, that I'm simply unaware of?

For comparison and completeness, here's the Devel::Peek output when -T is used:

$ perl -Te 'use Devel::Peek; my $x = $ENV{PATH}; Dump $x' SV = PVMG(0x8000c8850) at 0x80008b7d8 REFCNT = 1 FLAGS = (GMG,SMG,POK,IsCOW,pPOK) IV = 0 NV = 0 PV = 0x80008de60 "... long list of pathnames ..."\0 CUR = 2026 LEN = 2028 COW_REFCNT = 1 MAGIC = 0x8000447c0 MG_VIRTUAL = &PL_vtbl_taint MG_TYPE = PERL_MAGIC_taint(t) MG_LEN = 1 $ perl -Te 'use Devel::Peek; my $x = q{$ENV{PATH}}; Dump $x' SV = PV(0x800004670) at 0x80008bee8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x800090220 "$ENV{PATH}"\0 CUR = 10 LEN = 12 COW_REFCNT = 1

There's no change for the untainted $x. The tainted version has additional FLAGS and a new MAGIC section. I had found PERL_MAGIC_taint in perlguts and originally thought that was related to PVMG (but maybe that's wrong).

— Ken