Skip to content

Commit 7178397

Browse files
committed
Merge branch 'master' into phpng
* master: (29 commits) drop exec perm on doc files fix test for 5.4/5.5 restore correct behavior of DateTime fix test use invalid code add test for previous fix NEWS NEWS NEWS Fix regression introduce in fix for bug #67118 update news update NEWS Fix tests Fix possible segfault depending on memory location... Fixed startup segfault in non-debug builds Fixes issue #87 PHP 5.4/5.5 compability in phpdbg_watch.c fix gcov data with some locales (again) fix gcov data with some locales (again) fix gcov data with some locales (again) Update NEWS Fixed startup segfault in non-debug builds Fixes issue #87 ...
2 parents 1b89168 + e160976 commit 7178397

File tree

15 files changed

+172
-62
lines changed

15 files changed

+172
-62
lines changed

Makefile.gcov

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ php_lcov.info: lcov-test
1414
@rm -rf lcov_data/
1515
@$(mkinstalldirs) lcov_data/
1616
@echo
17-
-@files=`find . -name \*.gcda -o -name \*.gcno -o -name \*.da -o -name \*.c -o -name \*.h | sed -e 's/^\.\///' | sed -e 's/\.gcda//g' -e 's/\.gcno//g' -e 's/\.da//g' | $(EGREP) $(LCOV_INCLUDE) | sed -e 's/.libs/ZZZZ/g' | sort -h | sed -e 's/ZZZZ/.libs/g' | uniq` ;\
17+
-@files=`find . -name \*.gcda -o -name \*.gcno -o -name \*.da -o -name \*.c -o -name \*.h | sed -e 's/^\.\///' | sed -e 's/\.gcda//g' -e 's/\.gcno//g' -e 's/\.da//g' | $(EGREP) $(LCOV_INCLUDE) | sed -e 's/.libs/zzzz/g' | sort | sed -e 's/zzzz/.libs/g' | uniq` ;\
1818
for x in $$files; do \
1919
echo -n . ;\
2020
y=`echo $$x | sed -e 's!\.libs/!!'`; \

README.namespaces

100755100644
File mode changed.

UPGRADING

100755100644
File mode changed.

ext/date/php_date.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,8 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str,
25292529
err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message);
25302530
}
25312531
if (err && err->error_count) {
2532+
timelib_time_dtor(dateobj->time);
2533+
dateobj->time = 0;
25322534
return 0;
25332535
}
25342536

ext/date/tests/bug67118.phpt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug #67118 php-cgi crashes regularly on IIS 7
2+
Bug #67118 crashes in DateTime when this used after failed __construct
33
--INI--
44
date.timezone=Europe/Berlin
55
--FILE--
@@ -11,17 +11,16 @@ class mydt extends datetime
1111
if (!empty($tz) && !is_object($tz)) {
1212
$tz = new DateTimeZone($tz);
1313
}
14-
15-
@parent::__construct($time, $tz);
14+
try {
15+
@parent::__construct($time, $tz);
16+
} catch (Exception $e) {
17+
echo "Bad date" . $this->format("Y") . "\n";
18+
}
1619
}
1720

1821
};
1922

2023
new mydt("Funktionsansvarig rådgivning och juridik", "UTC");
24+
?>
2125
--EXPECTF--
22-
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (Funktionsansvarig rådgivning och juridik) at position 0 (F): The timezone could not be found in the database' in %sbug67118.php:%d
23-
Stack trace:
24-
#0 %sbug67118.php(%d): DateTime->__construct('Funktionsansvar...', Object(DateTimeZone))
25-
#1 %sbug67118.php(%d): mydt->__construct('Funktionsansvar...', 'UTC')
26-
#2 {main}
27-
thrown in %sbug67118.php on line %d
26+
Fatal error: Call to a member function format() on a non-object in %sbug67118.php on line %d

ext/date/tests/bug67118_2.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Regression introduce in fix for Bug #67118 - Invalid code
3+
--INI--
4+
date.timezone=Europe/Paris
5+
--FILE--
6+
<?php
7+
class Foo extends DateTime {
8+
public function __construct($time = null) {
9+
$tz = new DateTimeZone('UTC');
10+
try {
11+
echo "First try\n";
12+
parent::__construct($time, $tz);
13+
return;
14+
} catch (Exception $e) {
15+
echo "Second try\n";
16+
parent::__construct($time.'C', $tz);
17+
}
18+
}
19+
}
20+
$date = '12 Sep 2007 15:49:12 UT';
21+
var_dump(new Foo($date));
22+
?>
23+
Done
24+
--EXPECTF--
25+
First try
26+
Second try
27+
NULL
28+
Done

ext/fileinfo/libmagic/cdf.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "file.h"
3636

3737
#ifndef lint
38-
FILE_RCSID("@(#)$File: cdf.c,v 1.53 2013/02/26 16:20:42 christos Exp $")
38+
FILE_RCSID("@(#)$File: cdf.c,v 1.55 2014/02/27 23:26:17 christos Exp $")
3939
#endif
4040

4141
#include <assert.h>
@@ -365,10 +365,10 @@ cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
365365
size_t ss = CDF_SHORT_SEC_SIZE(h);
366366
size_t pos = CDF_SHORT_SEC_POS(h, id);
367367
assert(ss == len);
368-
if (pos > CDF_SEC_SIZE(h) * sst->sst_len) {
368+
if (pos + len > CDF_SEC_SIZE(h) * sst->sst_len) {
369369
DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
370370
SIZE_T_FORMAT "u\n",
371-
pos, CDF_SEC_SIZE(h) * sst->sst_len));
371+
pos + len, CDF_SEC_SIZE(h) * sst->sst_len));
372372
return -1;
373373
}
374374
(void)memcpy(((char *)buf) + offs,
@@ -688,11 +688,13 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
688688

689689
int
690690
cdf_read_short_stream(const cdf_info_t *info, const cdf_header_t *h,
691-
const cdf_sat_t *sat, const cdf_dir_t *dir, cdf_stream_t *scn)
691+
const cdf_sat_t *sat, const cdf_dir_t *dir, cdf_stream_t *scn,
692+
const cdf_directory_t **root)
692693
{
693694
size_t i;
694695
const cdf_directory_t *d;
695696

697+
*root = NULL;
696698
for (i = 0; i < dir->dir_len; i++)
697699
if (dir->dir_tab[i].d_type == CDF_DIR_TYPE_ROOT_STORAGE)
698700
break;
@@ -701,6 +703,7 @@ cdf_read_short_stream(const cdf_info_t *info, const cdf_header_t *h,
701703
if (i == dir->dir_len)
702704
goto out;
703705
d = &dir->dir_tab[i];
706+
*root = d;
704707

705708
/* If the it is not there, just fake it; some docs don't have it */
706709
if (d->d_stream_first_sector < 0)

ext/fileinfo/libmagic/cdf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ int cdf_read_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
300300
int cdf_read_ssat(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
301301
cdf_sat_t *);
302302
int cdf_read_short_stream(const cdf_info_t *, const cdf_header_t *,
303-
const cdf_sat_t *, const cdf_dir_t *, cdf_stream_t *);
303+
const cdf_sat_t *, const cdf_dir_t *, cdf_stream_t *,
304+
const cdf_directory_t **);
304305
int cdf_read_property_info(const cdf_stream_t *, const cdf_header_t *, uint32_t,
305306
cdf_property_info_t **, size_t *, size_t *);
306307
int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *,

ext/fileinfo/libmagic/readcdf.c

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "file.h"
2727

2828
#ifndef lint
29-
FILE_RCSID("@(#)$File: readcdf.c,v 1.37 2014/01/06 13:41:18 rrt Exp $")
29+
FILE_RCSID("@(#)$File: readcdf.c,v 1.40 2014/03/06 15:23:33 christos Exp $")
3030
#endif
3131

3232
#include <stdlib.h>
@@ -77,6 +77,40 @@ static const struct nv {
7777
# define strcasestr strstr
7878
#endif
7979

80+
static const struct cv {
81+
uint64_t clsid[2];
82+
const char *mime;
83+
} clsid2mime[] = {
84+
{
85+
#ifdef PHP_WIN32
86+
{ 0x00000000000c1084ui64, 0x46000000000000c0ui64 },
87+
#else
88+
{ 0x00000000000c1084LLU, 0x46000000000000c0LLU },
89+
#endif
90+
"x-msi",
91+
}
92+
}, clsid2desc[] = {
93+
{
94+
#ifdef PHP_WIN32
95+
{ 0x00000000000c1084ui64, 0x46000000000000c0ui64 },
96+
#else
97+
{ 0x00000000000c1084LLU, 0x46000000000000c0LLU },
98+
#endif
99+
"MSI Installer",
100+
},
101+
};
102+
103+
private const char *
104+
cdf_clsid_to_mime(const uint64_t clsid[2], const struct cv *cv)
105+
{
106+
size_t i;
107+
for (i = 0; cv[i].mime != NULL; i++) {
108+
if (clsid[0] == cv[i].clsid[0] && clsid[1] == cv[i].clsid[1])
109+
return cv[i].mime;
110+
}
111+
return NULL;
112+
}
113+
80114
private const char *
81115
cdf_app_to_mime(const char *vbuf, const struct nv *nv)
82116
{
@@ -95,7 +129,7 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
95129

96130
private int
97131
cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
98-
size_t count)
132+
size_t count, const cdf_directory_t *root_storage)
99133
{
100134
size_t i;
101135
cdf_timestamp_t tp;
@@ -107,6 +141,9 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
107141

108142
memset(&ts, 0, sizeof(ts));
109143

144+
if (!NOTMIME(ms) && root_storage)
145+
str = cdf_clsid_to_mime(root_storage->d_storage_uuid, clsid2mime);
146+
110147
for (i = 0; i < count; i++) {
111148
cdf_print_property_name(buf, sizeof(buf), info[i].pi_id);
112149
switch (info[i].pi_type) {
@@ -163,7 +200,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
163200
buf, vbuf) == -1)
164201
return -1;
165202
}
166-
} else if (info[i].pi_id ==
203+
} else if (str == NULL && info[i].pi_id ==
167204
CDF_PROPERTY_NAME_OF_APPLICATION) {
168205
str = cdf_app_to_mime(vbuf, app2mime);
169206
}
@@ -217,7 +254,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
217254

218255
private int
219256
cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
220-
const cdf_stream_t *sst)
257+
const cdf_stream_t *sst, const cdf_directory_t *root_storage)
221258
{
222259
cdf_summary_info_header_t si;
223260
cdf_property_info_t *info;
@@ -228,6 +265,8 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
228265
return -1;
229266

230267
if (NOTMIME(ms)) {
268+
const char *str;
269+
231270
if (file_printf(ms, "Composite Document File V2 Document")
232271
== -1)
233272
return -1;
@@ -255,9 +294,15 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
255294
return -2;
256295
break;
257296
}
258-
}
297+
if (root_storage) {
298+
str = cdf_clsid_to_mime(root_storage->d_storage_uuid, clsid2desc);
299+
if (str)
300+
if (file_printf(ms, ", %s", str) == -1)
301+
return -2;
302+
}
303+
}
259304

260-
m = cdf_file_property_info(ms, info, count);
305+
m = cdf_file_property_info(ms, info, count, root_storage);
261306
free(info);
262307

263308
return m == -1 ? -2 : m;
@@ -275,6 +320,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
275320
int i;
276321
const char *expn = "";
277322
const char *corrupt = "corrupt: ";
323+
const cdf_directory_t *root_storage;
278324

279325
info.i_fd = fd;
280326
info.i_buf = buf;
@@ -308,7 +354,8 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
308354
goto out2;
309355
}
310356

311-
if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst)) == -1) {
357+
if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst,
358+
&root_storage)) == -1) {
312359
expn = "Cannot read short stream";
313360
goto out3;
314361
}
@@ -329,23 +376,21 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
329376
#ifdef CDF_DEBUG
330377
cdf_dump_summary_info(&h, &scn);
331378
#endif
332-
if ((i = cdf_file_summary_info(ms, &h, &scn)) < 0)
333-
expn = "Can't expand summary_info";
379+
if ((i = cdf_file_summary_info(ms, &h, &scn, root_storage)) < 0)
380+
expn = "Can't expand summary_info";
381+
334382
if (i == 0) {
335383
const char *str = NULL;
336384
cdf_directory_t *d;
337385
char name[__arraycount(d->d_name)];
338386
size_t j, k;
339-
for (j = 0; j < dir.dir_len; j++) {
387+
388+
for (j = 0; str == NULL && j < dir.dir_len; j++) {
340389
d = &dir.dir_tab[j];
341390
for (k = 0; k < sizeof(name); k++)
342391
name[k] = (char)cdf_tole2(d->d_name[k]);
343-
if (NOTMIME(ms))
344-
str = cdf_app_to_mime(name, name2desc);
345-
else
346-
str = cdf_app_to_mime(name, name2mime);
347-
if (str != NULL)
348-
break;
392+
str = cdf_app_to_mime(name,
393+
NOTMIME(ms) ? name2desc : name2mime);
349394
}
350395
if (NOTMIME(ms)) {
351396
if (str != NULL) {

sapi/phpdbg/phpdbg.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
159159
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], 8, NULL, php_phpdbg_destroy_bp_condition, 0);
160160
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], 8, NULL, NULL, 0);
161161

162-
phpdbg_setup_watchpoints(TSRMLS_C);
163-
164162
zend_hash_init(&PHPDBG_G(seek), 8, NULL, NULL, 0);
165163
zend_hash_init(&PHPDBG_G(registered), 8, NULL, php_phpdbg_destroy_registered, 0);
166164

@@ -879,6 +877,32 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) {
879877
}
880878
#endif
881879

880+
static inline zend_mm_heap *phpdbg_mm_get_heap() {
881+
zend_mm_heap *mm_heap;
882+
883+
TSRMLS_FETCH();
884+
885+
mm_heap = zend_mm_set_heap(NULL TSRMLS_CC);
886+
zend_mm_set_heap(mm_heap TSRMLS_CC);
887+
888+
return mm_heap;
889+
}
890+
891+
void *phpdbg_malloc_wrapper(size_t size)
892+
{
893+
return zend_mm_alloc(phpdbg_mm_get_heap(), size);
894+
}
895+
896+
void phpdbg_free_wrapper(void *p)
897+
{
898+
zend_mm_free(phpdbg_mm_get_heap(), p);
899+
}
900+
901+
void *phpdbg_realloc_wrapper(void *ptr, size_t size)
902+
{
903+
return zend_mm_realloc(phpdbg_mm_get_heap(), ptr, size);
904+
}
905+
882906
int main(int argc, char **argv) /* {{{ */
883907
{
884908
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
@@ -1221,23 +1245,22 @@ int main(int argc, char **argv) /* {{{ */
12211245
EXCEPTION_POINTERS *xp;
12221246
__try {
12231247
#endif
1224-
zend_mm_heap *mm_heap = zend_mm_set_heap(NULL TSRMLS_CC);
1225-
#if ZEND_DEBUG
1226-
if (!mm_heap->use_zend_alloc) {
1227-
mm_heap->_malloc = malloc;
1228-
mm_heap->_realloc = realloc;
1229-
mm_heap->_free = free;
1230-
#endif
1231-
PHPDBG_G(original_free_function) = mm_heap->_free;
1232-
mm_heap->_free = phpdbg_watch_efree;
1248+
zend_mm_heap *mm_heap = phpdbg_mm_get_heap();
1249+
1250+
if (mm_heap->use_zend_alloc) {
1251+
mm_heap->_malloc = phpdbg_malloc_wrapper;
1252+
mm_heap->_realloc = phpdbg_realloc_wrapper;
1253+
mm_heap->_free = phpdbg_free_wrapper;
12331254
mm_heap->use_zend_alloc = 0;
1234-
#if ZEND_DEBUG
12351255
}
1236-
#endif
1237-
zend_mm_set_heap(mm_heap TSRMLS_CC);
12381256

12391257
zend_activate(TSRMLS_C);
12401258

1259+
PHPDBG_G(original_free_function) = mm_heap->_free;
1260+
mm_heap->_free = phpdbg_watch_efree;
1261+
1262+
phpdbg_setup_watchpoints(TSRMLS_C);
1263+
12411264
#if defined(ZEND_SIGNALS) && !defined(_WIN32)
12421265
zend_try {
12431266
zend_signal_activate(TSRMLS_C);

sapi/phpdbg/phpdbg_watch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void phpdbg_setup_watchpoints(TSRMLS_D) {
580580
zend_llist_init(&PHPDBG_G(watchlist_mem), sizeof(void *), phpdbg_watch_mem_dtor, 1);
581581
phpdbg_btree_init(&PHPDBG_G(watchpoint_tree), sizeof(void *) * 8);
582582
phpdbg_btree_init(&PHPDBG_G(watch_HashTables), sizeof(void *) * 8);
583-
_zend_hash_init(&PHPDBG_G(watchpoints), 8, phpdbg_watch_dtor, 0 ZEND_FILE_LINE_CC);
583+
zend_hash_init(&PHPDBG_G(watchpoints), 8, NULL, phpdbg_watch_dtor, 0 ZEND_FILE_LINE_CC);
584584
}
585585

586586
static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump TSRMLS_DC) {

sapi/phpdbg/tests/commands/0002_set.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# setting notice color
1010
# Failed to find breakpoint #0
1111
# oplog disabled
12-
# not enabled
1312
# opened oplog test.log
1413
# nothing
1514
#################################################
@@ -19,5 +18,4 @@ set color notice none
1918
set prompt promot>
2019
set break 0
2120
set oplog
22-
set oplog 0
2321
set oplog test.log

0 commit comments

Comments
 (0)