Skip to content

fix heuristics for setsockopt's OPTVAL argument#18761

Closed
t-a-k wants to merge 3 commits into
Perl:bleadfrom
t-a-k:gh18642
Closed

fix heuristics for setsockopt's OPTVAL argument#18761
t-a-k wants to merge 3 commits into
Perl:bleadfrom
t-a-k:gh18642

Conversation

@t-a-k

@t-a-k t-a-k commented May 1, 2021

Copy link
Copy Markdown
Contributor

pp_ssockopt used to treat its last argument (OPTVAL) as a packed string whenever it has string slot set (SvPOKp), but this would be confused if the argument is an integer but had cached stringified value.
This PR will make it treat OPTVAL as a packed string only when it does not contain any valid public numeric value.

Will fix #18642.

@jkeenan

jkeenan commented Jul 3, 2022

Copy link
Copy Markdown
Contributor

pp_ssockopt used to treat its last argument (OPTVAL) as a packed string whenever it has string slot set (SvPOKp), but this would be confused if the argument is an integer but had cached stringified value. This PR will make it treat OPTVAL as a packed string only when it does not contain any valid public numeric value.

Will fix #18642.

@t-a-k, this pull request has not received any support since being made in May 2021. It has acquired merge conflicts. Do you still want to pursue it?

@haarg

haarg commented Jul 3, 2022

Copy link
Copy Markdown
Contributor

I believe this should be changed to only check SvPOK. It never should have been checking the private flag to begin with, and on 5.36+ that change would also prevent it from inadvertently being treated as a string.

@t-a-k

t-a-k commented Jul 4, 2022

Copy link
Copy Markdown
Contributor Author

I'm sorry for leaving this PR unmaintained. I will merge it with blead and push again.

@t-a-k

t-a-k commented Jul 5, 2022

Copy link
Copy Markdown
Contributor Author

I believe this should be changed to only check SvPOK.

Thanks for your comment. I've changed the patch to check SvPOK and pushed it.

I also added a test for #19892 which I believe this PR will fix.

@tonycoz

tonycoz commented Jul 7, 2022

Copy link
Copy Markdown
Contributor

This will treat boolean values as a string, which I don't think is desirable. You can check for that with SvIsBOOL(sv).

It also needs to be rebased.

t-a-k added 3 commits July 8, 2022 18:38
setsockopt (pp_ssockopt) used to treat its last argument (OPTVAL) as
a packed string whenever it has string slot set (SvPOKp), but this
would be confused if the argument is an integer but had cached
stringified value.  Now it will treat OPTVAL as a packed string
only when it is originally created as a string, using Perl 5.36+'s
new (internal) feature where POK flag indicates whether the SV started
as a string.

Will fix GH Perl#18642.
Boolean values used to be treated as string, but this is not desirable.
(thanks to @tonycoz)

Also added tests for this.
@t-a-k

t-a-k commented Jul 8, 2022

Copy link
Copy Markdown
Contributor Author

Thank you for your advice. I've modified and rebased the patch and force-pushed it.

@tonycoz

tonycoz commented Jul 11, 2022

Copy link
Copy Markdown
Contributor

applied as 0cb18e0, f192c22 and b046062

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.

setsockopt in IO::Socket fooled by scalars with string slot set

4 participants