Skip to content

Instantly share code, notes, and snippets.

@zsprackett
Created June 25, 2017 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zsprackett/8197f0242040c2e43d8d800521f09e22 to your computer and use it in GitHub Desktop.
Save zsprackett/8197f0242040c2e43d8d800521f09e22 to your computer and use it in GitHub Desktop.
diff -ruN php-5.6.30.orig/Zend/zend_language_scanner.c php-5.6.30/Zend/zend_language_scanner.c
--- php-5.6.30.orig/Zend/zend_language_scanner.c 2017-01-18 19:17:47.000000000 -0500
+++ php-5.6.30/Zend/zend_language_scanner.c 2017-06-25 18:47:16.000000000 -0400
@@ -38,6 +38,9 @@
#ifdef PHP_WIN32
# include <Winuser.h>
#endif
+#ifndef _WIN32
+# include "zend_signal.h"
+#endif
#include "zend_alloc.h"
#include <zend_language_parser.h>
#include "zend_compile.h"
@@ -125,6 +128,14 @@
BEGIN_EXTERN_C()
+#ifndef _WIN32
+static sigjmp_buf sigbus_jmpbuf;
+static void sigbus_handler (int sig, siginfo_t *siginfo, void *ptr)
+{
+ siglongjmp(sigbus_jmpbuf, 1);
+}
+#endif
+
static size_t encoding_filter_script_to_internal(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length TSRMLS_DC)
{
const zend_encoding *internal_encoding = zend_multibyte_get_internal_encoding(TSRMLS_C);
@@ -580,6 +591,30 @@
}
compilation_successful=0;
} else {
+#ifndef _WIN32
+ struct sigaction sigbus_signal;
+ struct sigaction old_sigbus_signal;
+
+ memset(&sigbus_signal, 0, sizeof(sigbus_signal));
+ memset(&old_sigbus_signal, 0, sizeof(old_sigbus_signal));
+ sigbus_signal.sa_sigaction = sigbus_handler;
+ sigbus_signal.sa_flags = SA_SIGINFO;
+#endif
+
+#if defined(ZEND_SIGNALS) && !defined(_WIN32)
+ zend_try { zend_sigaction(SIGBUS, &sigbus_signal, &old_sigbus_signal TSRMLS_CC); } zend_end_try();
+#elif !defined(_WIN32)
+ sigaction(SIGBUS, &sigbus_signal, &old_sigbus_signal);
+#endif
+
+#ifndef _WIN32
+ if (sigsetjmp(sigbus_jmpbuf, 1)) {
+ if (file_handle->type != ZEND_HANDLE_STREAM) {
+ file_handle->type = ZEND_HANDLE_STREAM;
+ }
+ }
+#endif
+
init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC);
CG(in_compilation) = 1;
CG(active_op_array) = op_array;
@@ -592,6 +627,12 @@
zend_bailout();
}
compilation_successful=1;
+
+#if defined(ZEND_SIGNALS) && !defined(_WIN32)
+ zend_try { zend_sigaction(SIGBUS, &old_sigbus_signal, 0 TSRMLS_CC); } zend_end_try();
+#elif !defined(_WIN32)
+ sigaction(SIGBUS, &old_sigbus_signal, 0);
+#endif
}
if (retval) {
diff -ruN php-5.6.30.orig/Zend/zend_language_scanner.l php-5.6.30/Zend/zend_language_scanner.l
--- php-5.6.30.orig/Zend/zend_language_scanner.l 2017-01-18 19:17:47.000000000 -0500
+++ php-5.6.30/Zend/zend_language_scanner.l 2017-06-25 18:46:45.000000000 -0400
@@ -36,6 +36,9 @@
#ifdef PHP_WIN32
# include <Winuser.h>
#endif
+#ifndef _WIN32
+# include "zend_signal.h"
+#endif
#include "zend_alloc.h"
#include <zend_language_parser.h>
#include "zend_compile.h"
@@ -123,6 +126,14 @@
BEGIN_EXTERN_C()
+#ifndef _WIN32
+static sigjmp_buf sigbus_jmpbuf;
+static void sigbus_handler (int sig, siginfo_t *siginfo, void *ptr)
+{
+ siglongjmp(sigbus_jmpbuf, 1);
+}
+#endif
+
static size_t encoding_filter_script_to_internal(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length TSRMLS_DC)
{
const zend_encoding *internal_encoding = zend_multibyte_get_internal_encoding(TSRMLS_C);
@@ -578,6 +589,30 @@
}
compilation_successful=0;
} else {
+#ifndef _WIN32
+ struct sigaction sigbus_signal;
+ struct sigaction old_sigbus_signal;
+
+ memset(&sigbus_signal, 0, sizeof(sigbus_signal));
+ memset(&old_sigbus_signal, 0, sizeof(old_sigbus_signal));
+ sigbus_signal.sa_sigaction = sigbus_handler;
+ sigbus_signal.sa_flags = SA_SIGINFO;
+#endif
+
+#if defined(ZEND_SIGNALS) && !defined(_WIN32)
+ zend_try { zend_sigaction(SIGBUS, &sigbus_signal, &old_sigbus_signal TSRMLS_CC); } zend_end_try();
+#elif !defined(_WIN32)
+ sigaction(SIGBUS, &sigbus_signal, &old_sigbus_signal);
+#endif
+
+#ifndef _WIN32
+ if (sigsetjmp(sigbus_jmpbuf, 1)) {
+ if (file_handle->type != ZEND_HANDLE_STREAM) {
+ file_handle->type = ZEND_HANDLE_STREAM;
+ }
+ }
+#endif
+
init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC);
CG(in_compilation) = 1;
CG(active_op_array) = op_array;
@@ -590,6 +625,12 @@
zend_bailout();
}
compilation_successful=1;
+
+#if defined(ZEND_SIGNALS) && !defined(_WIN32)
+ zend_try { zend_sigaction(SIGBUS, &old_sigbus_signal, 0 TSRMLS_CC); } zend_end_try();
+#elif !defined(_WIN32)
+ sigaction(SIGBUS, &old_sigbus_signal, 0);
+#endif
}
if (retval) {
@neklaf
Copy link

neklaf commented Oct 24, 2017

Hello Zac,
we are trying to apply your patch to fix this bug https://bugs.php.net/bug.php?id=71377 in our platform but unfortunately we get the following error:

/usr/local/src$ patch -p0 < php-5.6.30-php52752.patch
patching file php-5.6.30/Zend/zend_language_scanner.c
Hunk #1 FAILED at 38 (different line endings).
Hunk #2 FAILED at 125 (different line endings).
Hunk #3 FAILED at 580 (different line endings).
Hunk #4 FAILED at 592 (different line endings).
4 out of 4 hunks FAILED -- saving rejects to file php-5.6.30/Zend/zend_language_scanner.c.rej
patching file php-5.6.30/Zend/zend_language_scanner.l

Our patch version:
$ patch -v
GNU patch 2.7.5

We also tried --ignore-whitespace flag with the same result:
$ patch -p0 --ignore-whitespace < php-5.6.30-php52752.patch
patching file php-5.6.30/Zend/zend_language_scanner.c
Hunk #1 FAILED at 38 (different line endings).
Hunk #2 FAILED at 125 (different line endings).
Hunk #3 FAILED at 580 (different line endings).
Hunk #4 FAILED at 592 (different line endings).
4 out of 4 hunks FAILED -- saving rejects to file php-5.6.30/Zend/zend_language_scanner.c.rej
patching file php-5.6.30/Zend/zend_language_scanner.l

We have downloaded php-5.6.30.tar.bz2 file from PHP servers so Zend/zend_language_scanner.c file should have the same content.

May be you could assist us with this issue.

Thanks for this patch anyway.

Regards,
Aitor

@neklaf
Copy link

neklaf commented Oct 30, 2017

Hello Zac,

I applied this patch manually and it works like a charm.

Thank you very much!

Regards,
Aitor

@robinmulder
Copy link

Here is a patch that should apply cleanly to PHP 5.6.33.

https://gist.github.com/robinmulder/916a7b5f059870d1348e4b5423a2ef7e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment