Skip to content

Commit f6f0f65

Browse files
committed
- Fixed bug #48930 (__COMPILER_HALT_OFFSET__ incorrect in PHP >= 5.3)
1 parent f241995 commit f6f0f65

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

Zend/zend_language_scanner.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Generated by re2c 0.13.5 on Tue Jun 29 22:47:47 2010 */
1+
/* Generated by re2c 0.13.5 on Tue Jun 29 23:34:41 2010 */
22
#line 1 "Zend/zend_language_scanner.l"
33
/*
44
+----------------------------------------------------------------------+
@@ -141,8 +141,10 @@ static void yy_pop_state(TSRMLS_D)
141141
static void yy_scan_buffer(char *str, unsigned int len TSRMLS_DC)
142142
{
143143
YYCURSOR = (YYCTYPE*)str;
144-
SCNG(yy_start) = YYCURSOR;
145144
YYLIMIT = YYCURSOR + len;
145+
if (!SCNG(yy_start)) {
146+
SCNG(yy_start) = YYCURSOR;
147+
}
146148
}
147149

148150
void startup_scanner(TSRMLS_D)
@@ -243,7 +245,14 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC)
243245
ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
244246
{
245247
char *file_path = NULL, *buf;
246-
size_t size;
248+
size_t size, offset = 0;
249+
250+
/* The shebang line was read, get the current position to obtain the buffer start */
251+
if (CG(start_lineno) == 2 && file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
252+
if ((offset = ftell(file_handle->handle.fp)) == -1) {
253+
offset = 0;
254+
}
255+
}
247256

248257
if (zend_stream_fixup(file_handle, &buf, &size TSRMLS_CC) == FAILURE) {
249258
return FAILURE;
@@ -259,6 +268,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
259268

260269
/* Reset the scanner for scanning the new file */
261270
SCNG(yy_in) = file_handle;
271+
SCNG(yy_start) = NULL;
262272

263273
if (size != -1) {
264274
#ifdef ZEND_MULTIBYTE
@@ -277,9 +287,10 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
277287
} else {
278288
SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_size) TSRMLS_CC);
279289
}
280-
290+
SCNG(yy_start) = SCNG(script_filtered) - offset;
281291
yy_scan_buffer((char *)SCNG(script_filtered), SCNG(script_filtered_size) TSRMLS_CC);
282292
#else /* !ZEND_MULTIBYTE */
293+
SCNG(yy_start) = buf - offset;
283294
yy_scan_buffer(buf, size TSRMLS_CC);
284295
#endif /* ZEND_MULTIBYTE */
285296
} else {
@@ -421,6 +432,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D
421432
memset(str->value.str.val + str->value.str.len, 0, ZEND_MMAP_AHEAD);
422433

423434
SCNG(yy_in)=NULL;
435+
SCNG(yy_start) = NULL;
424436

425437
#ifdef ZEND_MULTIBYTE
426438
SCNG(script_org) = (unsigned char *)estrdup(str->value.str.val);
@@ -3514,7 +3526,7 @@ int lex_scan(zval *zendlval TSRMLS_DC)
35143526
++YYCURSOR;
35153527
YYDEBUG(246, *YYCURSOR);
35163528
yyleng = YYCURSOR - SCNG(yy_text);
3517-
#line 1291 "Zend/zend_language_scanner.l"
3529+
#line 1303 "Zend/zend_language_scanner.l"
35183530
{
35193531
return T_SR_EQUAL;
35203532
}

Zend/zend_language_scanner.l

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ static void yy_pop_state(TSRMLS_D)
139139
static void yy_scan_buffer(char *str, unsigned int len TSRMLS_DC)
140140
{
141141
YYCURSOR = (YYCTYPE*)str;
142-
SCNG(yy_start) = YYCURSOR;
143142
YYLIMIT = YYCURSOR + len;
143+
if (!SCNG(yy_start)) {
144+
SCNG(yy_start) = YYCURSOR;
145+
}
144146
}
145147

146148
void startup_scanner(TSRMLS_D)
@@ -241,7 +243,14 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC)
241243
ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
242244
{
243245
char *file_path = NULL, *buf;
244-
size_t size;
246+
size_t size, offset = 0;
247+
248+
/* The shebang line was read, get the current position to obtain the buffer start */
249+
if (CG(start_lineno) == 2 && file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
250+
if ((offset = ftell(file_handle->handle.fp)) == -1) {
251+
offset = 0;
252+
}
253+
}
245254

246255
if (zend_stream_fixup(file_handle, &buf, &size TSRMLS_CC) == FAILURE) {
247256
return FAILURE;
@@ -257,6 +266,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
257266

258267
/* Reset the scanner for scanning the new file */
259268
SCNG(yy_in) = file_handle;
269+
SCNG(yy_start) = NULL;
260270

261271
if (size != -1) {
262272
#ifdef ZEND_MULTIBYTE
@@ -275,9 +285,10 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
275285
} else {
276286
SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_size) TSRMLS_CC);
277287
}
278-
288+
SCNG(yy_start) = SCNG(script_filtered) - offset;
279289
yy_scan_buffer((char *)SCNG(script_filtered), SCNG(script_filtered_size) TSRMLS_CC);
280290
#else /* !ZEND_MULTIBYTE */
291+
SCNG(yy_start) = buf - offset;
281292
yy_scan_buffer(buf, size TSRMLS_CC);
282293
#endif /* ZEND_MULTIBYTE */
283294
} else {
@@ -419,6 +430,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D
419430
memset(str->value.str.val + str->value.str.len, 0, ZEND_MMAP_AHEAD);
420431

421432
SCNG(yy_in)=NULL;
433+
SCNG(yy_start) = NULL;
422434

423435
#ifdef ZEND_MULTIBYTE
424436
SCNG(script_org) = (unsigned char *)estrdup(str->value.str.val);

0 commit comments

Comments
 (0)