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/mysqlnd: Refactor usage of strlcpy() #17185

Merged
merged 3 commits into from
Dec 28, 2024
Merged

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Dec 16, 2024

The two calls that MySQLnd does to this handler all pass a buffer the same size as the error_msg field Thus we know that we can just memcpy the error message into the buffer.

The two calls that MySQLnd does to this handler all pass a buffer the same size as the error_msg field
Thus we know that we can just memcpy the error message into the buffer.
@Girgias Girgias marked this pull request as ready for review December 17, 2024 00:25
ext/mysqlnd/mysqlnd_loaddata.c Show resolved Hide resolved
ext/mysqlnd/mysqlnd_loaddata.c Outdated Show resolved Hide resolved

DBG_ENTER("mysqlnd_local_infile_read");

count = (int) php_stream_read(info->fd, (char *) buf, buf_len);
ssize_t count = php_stream_read(info->fd, (char *) buf, buf_len);
Copy link
Member

Choose a reason for hiding this comment

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

The return type of int mysqlnd_local_infile_read() should be changed as well, otherwise the count < 0 check bellow may be false, but the return value may still be < 0 due to conversion to int.

Copy link
Member

Choose a reason for hiding this comment

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

Where does the conversion to int take place?

Copy link
Member

Choose a reason for hiding this comment

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

It happens when returning count, as the return type is int

Copy link
Member

Choose a reason for hiding this comment

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

It's an unrelated change so it should be probably removed from this PR and different PR created for this.

@bukka
Copy link
Member

bukka commented Dec 22, 2024

Why is this actually being done? I understand that strlcpy might have slightly bigger overhead and maybe not supported on all platfoms but I don't exactly understand why it should be done here (error handling part)? It seems kind of like waste of time to even review this or am I missing anything important?

@Girgias
Copy link
Member Author

Girgias commented Dec 23, 2024

Because strlcpy(3) is just bad, [1] and barely used within php-src (<50 usages). There is a reason it is not part of the C standard.

[1] https://nrk.neocities.org/articles/not-a-fan-of-strlcpy

@kamil-tekiela
Copy link
Member

I think it would be fine to merge this but maybe without the ssize_t change.

@Girgias
Copy link
Member Author

Girgias commented Dec 23, 2024

I'm just on holiday for the Xmas break, I'll get round to updating the PR after it (possibly on the 27th)

@Girgias Girgias merged commit 6ef58da into php:master Dec 28, 2024
10 checks passed
@Girgias Girgias deleted the mysqlnd-strlcpy branch December 28, 2024 23:00
@bukka
Copy link
Member

bukka commented Dec 29, 2024

Well I don't see how it's worse than strcpy and it's available in almost any libc (even glibc added it...) AFAIC. I don't have a big issue with removal though. Just thought that there might be more important things to do.

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.

4 participants