Skip to content

Guard against NULL token in first-entry of collection parse functions#339

Open
SAY-5 wants to merge 1 commit into
yaml:masterfrom
SAY-5:fix-null-token-first-collection-entry
Open

Guard against NULL token in first-entry of collection parse functions#339
SAY-5 wants to merge 1 commit into
yaml:masterfrom
SAY-5:fix-null-token-first-collection-entry

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 10, 2026

Copy link
Copy Markdown

The four collection-entry parse functions call PEEK_TOKEN in their if (first) block and dereference the result via token->start_mark without checking for NULL. PEEK_TOKEN returns NULL when yaml_parser_fetch_more_tokens fails, so a read or allocation error there causes a NULL dereference before the mark is pushed.

Every other PEEK_TOKEN site in parser.c already guards with if (!token) return 0; (including the very next statement in each of these functions). This adds the same guard to the first-entry path in yaml_parser_parse_block_sequence_entry, yaml_parser_parse_block_mapping_key, yaml_parser_parse_flow_sequence_entry and yaml_parser_parse_flow_mapping_key.

Closes #337. The existing test suite still passes; a direct reproducer would need to inject a read failure mid-stream inside the scanner, which the current tests do not exercise.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Null Pointer Dereference in parser.c — first=1 path of 4 collection-entry functions

1 participant