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

ext/sockets: Additional refactorings to socket_set_option() #17186

Merged
merged 9 commits into from
Dec 29, 2024

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Dec 17, 2024

No description provided.

ext/sockets/sockets.c Outdated Show resolved Hide resolved
ext/sockets/sockets.c Outdated Show resolved Hide resolved
@Girgias
Copy link
Member Author

Girgias commented Dec 17, 2024

Don't think we have a CI set-up where TCP_FUNCTION_BLK exists.

@devnexen
Copy link
Member

gonna try your branch

--SKIPIF--
<?php

if (!defined('IPPROTO_TCP')) {
Copy link
Member

@devnexen devnexen Dec 17, 2024

Choose a reason for hiding this comment

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

IPPROTO_TCP had been translated into SOL_TCP, also no need to check its existence it s unconditionally set looking at the stub.

Copy link
Member

Choose a reason for hiding this comment

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

See my run of your new tests

image

@devnexen
Copy link
Member

Don't think we have a CI set-up where TCP_FUNCTION_BLK exists.

It is supported since FreeBSD 13.x, should be no problem.

@Girgias Girgias marked this pull request as ready for review December 17, 2024 19:15
}
struct accept_filter_arg af = {0};
strlcpy(af.af_name, Z_STRVAL_P(arg4), sizeof(af.af_name));
if (Z_STRLEN_P(arg4) > sizeof(af.af_name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should that be Z_STRLEN_P(arg4) >= sizeof(af.af_name) (or Z_STRLEN_P(arg4)+1 > sizeof(af.af_name)) to account for the null byte?

Copy link
Member

@devnexen devnexen Dec 22, 2024

Choose a reason for hiding this comment

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

Like here, it would be nice to have more explanations of why you feel we need to replace strlcpy with memcpy.
1/ It is easier to fall into overflows with memcpy as per Arnaud/my comments.
2/ If you want to check truncations, strlcpy return value can help in this.
3/ If this is performance gain and since those changes are mainly about FreeBSD parts, let's say we create a bunch of sockets and we set bbr tcp stack for each so how much of a difference it makes in practice (related buffers are respectively 32 and 16 larges) ? Albeit freebsd's memcpy finally caught up a lot in term of optimisations (highlighting the case for size <= 32 bytes here) since the 14.x release serie. In comparison our strlcpy version is very straightforward but today's compilers are smarter.

Whether the changes are justified, I do not think it is very urgent we can see after Xmas days no rush :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Because strlcpy() is bad as I just replied to that other thread, we also need to do extra work to instrumentalize this on top of using a non standard C function.

I don't mind adding a helper function if that's the concern.

Copy link
Member

@devnexen devnexen Dec 23, 2024

Choose a reason for hiding this comment

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

I see ... in this case you still need to address arnaud and my comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'll get round to it after the Xmas break :)

@Girgias Girgias requested a review from devnexen December 28, 2024 23:41
ext/sockets/sockets.c Outdated Show resolved Hide resolved
@Girgias Girgias merged commit 9eb2284 into php:master Dec 29, 2024
10 checks passed
@Girgias Girgias deleted the sockets-strlcpy branch December 29, 2024 12:18
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.

3 participants