Skip to content

Commit 0badc7d

Browse files
committed
Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined)
1 parent b053192 commit 0badc7d

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #81433 (DOMElement::setIdAttribute() called twice may remove ID).
77
(Viktor Volkov)
88

9+
- FFI:
10+
. Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not
11+
defined). (Dmitry)
12+
913
- PCRE:
1014
. Fixed bug #81424 (PCRE2 10.35 JIT performance regression). (cmb)
1115

ext/ffi/ffi.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ declaration_specifiers(zend_ffi_dcl *dcl):
147147

148148
specifier_qualifier_list(zend_ffi_dcl *dcl):
149149
"__extension__"?
150-
( ?{sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text)}
150+
( ?{sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text) || (dcl->flags & ZEND_FFI_DCL_TYPE_SPECIFIERS) == 0}
151151
( type_specifier(dcl)
152152
| type_qualifier(dcl)
153153
| attributes(dcl)

ext/ffi/ffi_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ static int parse_specifier_qualifier_list(int sym, zend_ffi_dcl *dcl) {
21902190
} else {
21912191
yy_error_sym("unexpected", sym);
21922192
}
2193-
} while ((YY_IN_SET(sym, (YY_VOID,YY_CHAR,YY_SHORT,YY_INT,YY_LONG,YY_FLOAT,YY_DOUBLE,YY_SIGNED,YY_UNSIGNED,YY__BOOL,YY__COMPLEX,YY_COMPLEX,YY___COMPLEX,YY___COMPLEX__,YY_STRUCT,YY_UNION,YY_ENUM,YY_ID,YY_CONST,YY___CONST,YY___CONST__,YY_RESTRICT,YY___RESTRICT,YY___RESTRICT__,YY_VOLATILE,YY___VOLATILE,YY___VOLATILE__,YY__ATOMIC,YY___ATTRIBUTE,YY___ATTRIBUTE__,YY___DECLSPEC,YY___CDECL,YY___STDCALL,YY___FASTCALL,YY___THISCALL,YY___VECTORCALL), "\000\000\376\377\377\107\360\017\000\000\000\002\000")) && (sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text)));
2193+
} while ((YY_IN_SET(sym, (YY_VOID,YY_CHAR,YY_SHORT,YY_INT,YY_LONG,YY_FLOAT,YY_DOUBLE,YY_SIGNED,YY_UNSIGNED,YY__BOOL,YY__COMPLEX,YY_COMPLEX,YY___COMPLEX,YY___COMPLEX__,YY_STRUCT,YY_UNION,YY_ENUM,YY_ID,YY_CONST,YY___CONST,YY___CONST__,YY_RESTRICT,YY___RESTRICT,YY___RESTRICT__,YY_VOLATILE,YY___VOLATILE,YY___VOLATILE__,YY__ATOMIC,YY___ATTRIBUTE,YY___ATTRIBUTE__,YY___DECLSPEC,YY___CDECL,YY___STDCALL,YY___FASTCALL,YY___THISCALL,YY___VECTORCALL), "\000\000\376\377\377\107\360\017\000\000\000\002\000")) && (sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text) || (dcl->flags & ZEND_FFI_DCL_TYPE_SPECIFIERS) == 0));
21942194
return sym;
21952195
}
21962196

ext/ffi/tests/bug79576.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #79576 ("TYPE *" shows unhelpful message when type is not defined)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('ffi')) die('skip ffi extension not available');
6+
if (PHP_DEBUG || getenv('SKIP_ASAN')) echo "xfail: FFI cleanup after parser error is nor implemented";
7+
?>
8+
--FILE--
9+
<?php
10+
try {
11+
FFI::cdef('struct tree *get_tree(const oid *, size_t, struct tree *);');
12+
} catch (Throwable $e) {
13+
echo get_class($e) . ": " . $e->getMessage()."\n";
14+
}
15+
try {
16+
FFI::cdef('struct tree *get_tree(oid, size_t, struct tree *);');
17+
} catch (Throwable $e) {
18+
echo get_class($e) . ": " . $e->getMessage()."\n";
19+
}
20+
try {
21+
FFI::cdef('
22+
typedef struct _simple_struct {
23+
const some_not_declared_type **property;
24+
} simple_struct;
25+
');
26+
} catch (Throwable $e) {
27+
echo get_class($e) . ": " . $e->getMessage()."\n";
28+
}
29+
?>
30+
DONE
31+
--EXPECT--
32+
FFI\ParserException: undefined C type 'oid' at line 1
33+
FFI\ParserException: undefined C type 'oid' at line 1
34+
FFI\ParserException: undefined C type 'some_not_declared_type' at line 3
35+
DONE

0 commit comments

Comments
 (0)