Merge pull request #4853 from StevenHessing/noddos
[feed/packages.git] / lang / php7 / patches / 1006-multiline-syslog.patch
1 commit 4d77af8d7d349b7b9e43082deb47c1469f450115
2 Author: Philip Prindeville <philipp@redfish-solutions.com>
3 Date: Fri Aug 18 12:05:44 2017 -0600
4
5 Backport of fix for Issue #74860
6
7 diff --git a/configure.in b/configure.in
8 index 9acf42b..559a274 100644
9 --- a/configure.in
10 +++ b/configure.in
11 @@ -1470,7 +1470,7 @@ PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
12 php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
13 strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
14 network.c php_open_temporary_file.c \
15 - output.c getopt.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
16 + output.c getopt.c php_syslog.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
17
18 PHP_ADD_SOURCES_X(main, fastcgi.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, PHP_FASTCGI_OBJS, no)
19
20 diff --git a/ext/standard/php_smart_string.h b/ext/standard/php_smart_string.h
21 index adb78c0..8d90688 100644
22 --- a/ext/standard/php_smart_string.h
23 +++ b/ext/standard/php_smart_string.h
24 @@ -146,4 +146,8 @@
25 #define smart_string_sets(dest, src) \
26 smart_string_setl((dest), (src), strlen(src));
27
28 +#define smart_string_reset(dest) do { \
29 + (dest)->len = 0; \
30 +} while (0)
31 +
32 #endif
33 diff --git a/main/php_syslog.c b/main/php_syslog.c
34 new file mode 100644
35 index 0000000..43d1f56
36 --- /dev/null
37 +++ b/main/php_syslog.c
38 @@ -0,0 +1,80 @@
39 +/*
40 + +----------------------------------------------------------------------+
41 + | PHP Version 7 |
42 + +----------------------------------------------------------------------+
43 + | Copyright (c) 2017 The PHP Group |
44 + +----------------------------------------------------------------------+
45 + | This source file is subject to version 3.01 of the PHP license, |
46 + | that is bundled with this package in the file LICENSE, and is |
47 + | available through the world-wide-web at the following url: |
48 + | http://www.php.net/license/3_01.txt |
49 + | If you did not receive a copy of the PHP license and are unable to |
50 + | obtain it through the world-wide-web, please send a note to |
51 + | license@php.net so we can mail you a copy immediately. |
52 + +----------------------------------------------------------------------+
53 + | Author: Philip Prindeville <philipp@redfish-solutions.com> |
54 + +----------------------------------------------------------------------+
55 +*/
56 +
57 +/* $Id$ */
58 +
59 +#include <stdio.h>
60 +#include <string.h>
61 +#include <assert.h>
62 +#include <stdlib.h>
63 +#include "php.h"
64 +#include "php_syslog.h"
65 +
66 +#include "zend.h"
67 +#include "ext/standard/php_smart_string.h"
68 +
69 +/*
70 + * The SCO OpenServer 5 Development System (not the UDK)
71 + * defines syslog to std_syslog.
72 + */
73 +
74 +#ifdef HAVE_STD_SYSLOG
75 +#define syslog std_syslog
76 +#endif
77 +
78 +PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
79 +{
80 + const char *ptr;
81 + unsigned char c;
82 + char *message = NULL;
83 + smart_string sbuf = {0};
84 + va_list args;
85 +
86 + va_start(args, format);
87 + vspprintf(&message, 0, format, args);
88 + va_end(args);
89 +
90 + for (ptr = message; ; ++ptr) {
91 + c = *ptr;
92 + if (c == '\0') {
93 + syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
94 + break;
95 + }
96 +
97 + if (c != '\n')
98 + smart_string_appendc(&sbuf, c);
99 + else {
100 + syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
101 + smart_string_reset(&sbuf);
102 + }
103 + }
104 +
105 + efree(message);
106 + smart_string_free(&sbuf);
107 +}
108 +
109 +/* }}} */
110 +
111 +/*
112 + * Local variables:
113 + * tab-width: 4
114 + * c-basic-offset: 4
115 + * End:
116 + * vim600: sw=4 ts=4 fdm=marker
117 + * vim<600: sw=4 ts=4
118 + */
119 diff --git a/main/php_syslog.h b/main/php_syslog.h
120 index 33f52a3..a09f98c 100644
121 --- a/main/php_syslog.h
122 +++ b/main/php_syslog.h
123 @@ -21,6 +21,8 @@
124 #ifndef PHP_SYSLOG_H
125 #define PHP_SYSLOG_H
126
127 +#include "php.h"
128 +
129 #ifdef PHP_WIN32
130 #include "win32/syslog.h"
131 #else
132 @@ -30,23 +32,8 @@
133 #endif
134 #endif
135
136 -/*
137 - * The SCO OpenServer 5 Development System (not the UDK)
138 - * defines syslog to std_syslog.
139 - */
140 -
141 -#ifdef syslog
142 -
143 -#ifdef HAVE_STD_SYSLOG
144 -#define php_syslog std_syslog
145 -#endif
146 -
147 -#undef syslog
148 -
149 -#endif
150 -
151 -#ifndef php_syslog
152 -#define php_syslog syslog
153 -#endif
154 +BEGIN_EXTERN_C()
155 +PHPAPI void php_syslog(int, const char *format, ...);
156 +END_EXTERN_C()
157
158 #endif
159 diff --git a/win32/build/config.w32 b/win32/build/config.w32
160 index 1269c6e..f766e53 100644
161 --- a/win32/build/config.w32
162 +++ b/win32/build/config.w32
163 @@ -237,7 +237,8 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
164 ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
165 php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
166 strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
167 - php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
168 + php_open_temporary_file.c output.c internal_functions.c php_sprintf.c \
169 + php_syslog.c");
170 ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
171 ADD_SOURCES("win32", "inet.c fnmatch.c sockets.c");
172