Skip to content

GH-10141: Fix typo #11624

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

Closed
wants to merge 1 commit into from
Closed

GH-10141: Fix typo #11624

wants to merge 1 commit into from

Conversation

petk
Copy link
Member

@petk petk commented Jul 7, 2023

In configure.ac check for function strerror_r defines constant HAVE_STRERROR_R.

The functionality was added in #10141 but I think that due to this change maybe PHP 8.3 version would be enough to fix it like this. Otherwise, in PHP 8.2 and 8.1 it will always do only this char *buf = strerror(errn);.

Edit: This needs to be adjusted a bit further due to unused result issue in the strerror_r() call.

In configure.ac check for function strerror_r defines constant
HAVE_STRERROR_R.
@petk petk requested a review from dstogov as a code owner July 7, 2023 16:57
dstogov referenced this pull request Jul 24, 2023
On x86_64 glibc memrchr() uses SSE/AVX CPU extensions and works much
faster then naive loop. On x86 32-bit we still use inlined version.

memrchr() is a GNU extension. Its prototype  becomes available when
<string.h> is included with defined _GNU_SOURCE macro. Previously, we
defined it in "php_config.h", but some sources may include <string.h>
befire it. To avod mess we also pass -D_GNU_SOURCE to C compiler.
@dstogov
Copy link
Member

dstogov commented Jul 24, 2023

Thanks for catching this. The patch should be targeted to PHP-8.1

@@ -1639,7 +1639,7 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *

ZEND_API ZEND_COLD ZEND_NORETURN void zend_strerror_noreturn(int type, int errn, const char *message)
{
#ifdef HAVE_STR_ERROR_R
#ifdef HAVE_STRERROR_R
char buf[1024];
strerror_r(errn, buf, sizeof(buf));
Copy link
Member

@jmikola jmikola Jul 24, 2023

Choose a reason for hiding this comment

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

@dstogov: I don't think this resolves the issue I mentioned in 067df26#commitcomment-121630134. The constant typo being fixed here was a separate issue that I overlooked entirely (great catch by @petk).

The GNU version of strerror_r(3) may return a pointer to an immutable string instead of storing the result in the buf parameter. The XSI version always sets buf and returns an integer to indicate success/error.

Again, I don't think this would result in a build error. The zend_error_noreturn() line below would just end up printing message and errn with nothing between since buf would remain empty.

Copy link
Member

Choose a reason for hiding this comment

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

since buf would remain empty

Correction: buf would be uninitialized. I was incorrectly thinking of of static/global vars when I wrote that, which are zero-allocated.

@petk
Copy link
Member Author

petk commented Aug 4, 2023

Just a quick update here: I haven't been able to check this one out yet due various strerror_r signatures and otherwise it does result in build failure (the Linux X64_release ZTS), so for PHP-8.1 we should rewrite this a bit further.

Can maybe @dunglas help us out a bit?

Not related to this issue exactly, but there seemed to be a continuation planned here based on the comment in Zend/Zend.m4:

Don't enable Zend Max Execution Timers by default until PHP 8.3 to not break the ABI

Or should the ZEND_MAX_EXECUTION_TIMERS be turned on by default in PHP-8.4?

@dunglas
Copy link
Member

dunglas commented Aug 4, 2023

Thanks for catching my typo and working on fixing this problem.
I can try to fix the build failure if needed.

Regarding the continuation, is has been done in #10778.

@dunglas
Copy link
Member

dunglas commented Aug 5, 2023

I fixed the issue in #11882. I wasn't aware of AC_FUNC_STRERROR_R but it's exactly what we need.

@petk
Copy link
Member Author

petk commented Aug 7, 2023

Perfect. Thank you @dunglas! I'll close this PR in favor of the above fix.

@petk petk closed this Aug 7, 2023
@petk petk deleted the patch-10141-strerror-r branch August 7, 2023 09:56
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