Skip to content

Fix bug #79075: FFI header parser chokes on comments #17082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Dec 7, 2024

The directives for FFI should be first in the file, which is fine, however sometimes there can be comments or whitespace before or between these defines. One practical example is for license information or when a user adds newlines before the directives "by accident". In these cases, it's quite confusing that the directives do not work properly.
To solve this, make the zend_ffi_parse_directives() aware of comments.

One alternative is to actually call back from the parser when parsing a define line instead of treating a # symbol like a comment.

The directives for FFI should be first in the file, which is fine,
however sometimes there can be comments or whitespace before or between
these defines. One practical example is for license information or when
a user adds newlines "by accident". In these cases, it's quite confusing
that the directives do not work properly.
To solve this, make the zend_ffi_parse_directives() aware of comments.
@nielsdos nielsdos marked this pull request as ready for review December 8, 2024 21:32
@nielsdos nielsdos requested a review from dstogov as a code owner December 8, 2024 21:32
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this makes sense.
Please check the possible OOB read bug,

ext/ffi/ffi.c Outdated
Comment on lines 4975 to 4978
while (*p && (*p != '*' || p[1] != '/')) {
p++;
}
p += 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may cause read after the terminating zero.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right of course, fixed

@nielsdos nielsdos closed this in 612a34c Dec 9, 2024
charmitro pushed a commit to wasix-org/php that referenced this pull request Mar 13, 2025
The directives for FFI should be first in the file, which is fine,
however sometimes there can be comments or whitespace before or between
these defines. One practical example is for license information or when
a user adds newlines "by accident". In these cases, it's quite confusing
that the directives do not work properly.
To solve this, make the zend_ffi_parse_directives() aware of comments.

Closes phpGH-17082.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants