php / php/php-src

Undefined behaviour in re2c lexers caused by unspecified default rule.

Open
#17,523 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: pdo (core) SAPI: phpdbg Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

Hi! [re2c author here] It came to my attention in this nixos thread that re2c emits a some serious warnings on the current code for the lexers, e.g. this one. When running re2c with -W (or version >= 4.0) you should see this:

sapi/phpdbg/phpdbg_lexer.l:80:20: warning: escape has no effect: '\.' [-Wuseless-escape]
sapi/phpdbg/phpdbg_lexer.l:64:0: warning: control flow in condition 'NORMAL' is undefined for strings that match
        '\x22 [\x0\xA]'
        '\x27 [\x0\xA]'
        '\x22 \x22 [\x0\x9-\xA\xD\x20\x23]'
...

In particular, -Wundefined-control-flow warning indicates really serious issues; it is documented here. The fix should be simple: add default rule <*> * { /* error handling / abort / etc. */ }. Ideally also simplify some too-complex constructs like GENERIC_ID which make it hard to understand what's going on.

Some other warnings report unreachable rules, which is also not good (there's some rule that you think is doing something, but it's not).

I'm happy to help with further investigation and fixing these issues. I do recommend enabling the warnings from now on for all lexers - new bugs keep crawling in as the lexer code changes.

PHP Version

HEAD

Operating System

NixOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with sapi/phpdbg/phpdbg_lexer.l and run re2c with -W to reproduce the undefined-control-flow, useless-escape, and unreachable-rule warnings. Inspect the lexer rules and the other affected lexers, then verify that default handling is defined and the relevant warnings are resolved or intentionally addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.