Skip to content

Commit 238caeb

Browse files
author
Jerome Loyet
committed
- Fixed bug #62205 (php-fpm segfaults (null passed to strstr))
1 parent ec4a1d5 commit 238caeb

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ PHP NEWS
6868
. Fixed bug #62160 (Add process.priority to set nice(2) priorities). (fat)
6969
. Fixed bug #61218 (FPM drops connection while receiving some binary values
7070
in FastCGI requests). (fat)
71+
. Fixed bug #62205 (php-fpm segfaults (null passed to strstr)). (fat)
7172

7273
- Intl
7374
. ResourceBundle constructor now accepts NULL for the first two arguments.

sapi/fpm/fpm/fpm_php.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,41 @@ int fpm_php_limit_extensions(char *path) /* {{{ */
257257
return 1; /* extension not found: not allowed */
258258
}
259259
/* }}} */
260+
261+
char* fpm_php_get_string_from_table(char *table, char *key TSRMLS_DC) /* {{{ */
262+
{
263+
zval **data, **tmp;
264+
char *string_key;
265+
uint string_len;
266+
ulong num_key;
267+
if (!table || !key) {
268+
return NULL;
269+
}
270+
271+
/* inspired from ext/standard/info.c */
272+
273+
zend_is_auto_global(table, strlen(table) TSRMLS_CC);
274+
275+
/* find the table and ensure it's an array */
276+
if (zend_hash_find(&EG(symbol_table), table, strlen(table) + 1, (void **) &data) == SUCCESS && Z_TYPE_PP(data) == IS_ARRAY) {
277+
278+
/* reset the internal pointer */
279+
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
280+
281+
/* parse the array to look for our key */
282+
while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) {
283+
/* ensure the key is a string */
284+
if (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING) {
285+
/* compare to our key */
286+
if (!strncmp(string_key, key, string_len)) {
287+
return Z_STRVAL_PP(tmp);
288+
}
289+
}
290+
zend_hash_move_forward(Z_ARRVAL_PP(data));
291+
}
292+
}
293+
294+
return NULL;
295+
}
296+
/* }}} */
297+

sapi/fpm/fpm/fpm_php.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void fpm_php_soft_quit();
4444
int fpm_php_init_main();
4545
int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode);
4646
int fpm_php_limit_extensions(char *path);
47+
char* fpm_php_get_string_from_table(char *table, char *key TSRMLS_DC);
4748

4849
#endif
4950

sapi/fpm/fpm/fpm_status.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "zlog.h"
1515
#include "fpm_atomic.h"
1616
#include "fpm_conf.h"
17+
#include "fpm_php.h"
1718
#include <ext/standard/html.h>
1819

1920
static char *fpm_status_uri = NULL;
@@ -125,13 +126,13 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
125126
}
126127

127128
/* full status ? */
128-
full = SG(request_info).request_uri && strstr(SG(request_info).query_string, "full");
129+
full = (fpm_php_get_string_from_table("_GET", "full" TSRMLS_CC) != NULL);
129130
short_syntax = short_post = NULL;
130131
full_separator = full_pre = full_syntax = full_post = NULL;
131132
encode = 0;
132133

133134
/* HTML */
134-
if (SG(request_info).query_string && strstr(SG(request_info).query_string, "html")) {
135+
if (fpm_php_get_string_from_table("_GET", "html" TSRMLS_CC)) {
135136
sapi_add_header_ex(ZEND_STRL("Content-Type: text/html"), 1, 1 TSRMLS_CC);
136137
time_format = "%d/%b/%Y:%H:%M:%S %z";
137138
encode = 1;
@@ -205,7 +206,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
205206
}
206207

207208
/* XML */
208-
} else if (SG(request_info).request_uri && strstr(SG(request_info).query_string, "xml")) {
209+
} else if (fpm_php_get_string_from_table("_GET", "xml" TSRMLS_CC)) {
209210
sapi_add_header_ex(ZEND_STRL("Content-Type: text/xml"), 1, 1 TSRMLS_CC);
210211
time_format = "%s";
211212
encode = 1;
@@ -256,7 +257,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
256257
}
257258

258259
/* JSON */
259-
} else if (SG(request_info).request_uri && strstr(SG(request_info).query_string, "json")) {
260+
} else if (fpm_php_get_string_from_table("_GET", "json" TSRMLS_CC)) {
260261
sapi_add_header_ex(ZEND_STRL("Content-Type: application/json"), 1, 1 TSRMLS_CC);
261262
time_format = "%s";
262263

0 commit comments

Comments
 (0)