Unparsed heredocs during string and list interpolation error recovery strand PM_LEX_HEREDOC
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start with the error-recovery paths in parse_string_part, parse_interpolated_symbol_array, and parse_interpolated_string_array, where the issue says PM_TOKEN_HEREDOC_START is sent to parser_lex instead of parse_heredoc. Trace how PM_LEX_EMBEXPR and PM_LEX_HEREDOC are managed on parser->lex_modes, then reproduce the supplied input and check that parsed node locations stay within the source length. Add regression coverage for the interpolation forms listed in the issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Fuzzing find on bdbd482dc.
When parse_statements(parser, PM_CONTEXT_EMBEXPR, ...) inside an interpolated string, regexp, backtick, %W[...] string array, or %I[...] symbol array stops early via context_recoverable (because it encounters a closing token belonging to an outer enclosing context, such as )), PM_LEX_EMBEXPR remains active on parser->lex_modes. The enclosing string/list loop then calls parse_string_part (or the token switch in parse_interpolated_symbol_array / parse_interpolated_string_array) to drain the remaining tokens of the unclosed interpolation.
When one of those remaining tokens is PM_TOKEN_HEREDOC_START, parse_string_part, parse_interpolated_symbol_array, and parse_interpolated_string_array hit their default: error-recovery branch and call parser_lex(parser) instead of parse_heredoc. This strands PM_LEX_HEREDOC on parser->lex_modes, which later rewinds parser->next_start backwards in the middle of parsing a subsequent construct and underflows uint32_t location.length.
Reproduction
(Interactive simulation in Prism Loupe)
#include "prism.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
static pm_visit_result_t
check_bounds(const pm_node_t *node, void *data) {
size_t source_len = *(const size_t *) data;
uint64_t end = (uint64_t) node->location.start + (uint64_t) node->location.length;
if (end > source_len) {
printf(
"%-16s start=%" PRIu32 " length=%" PRIu32 " (0x%08" PRIx32 ") end=%" PRIu64 " > source_len=%zu\n",
pm_node_type(node->type),
node->location.start,
node->location.length,
node->location.length,
end,
source_len
);
}
return PM_VISIT_DESCEND;
}
int main(void) {
const char *src = "->x:\"#{)<<\"\n#{f\n\"#{a}\"C{";
size_t len = strlen(src);
pm_arena_t *arena = pm_arena_new();
pm_parser_t *parser = pm_parser_new(arena, (const uint8_t *) src, len, NULL);
pm_node_t *root = pm_parse(parser);
pm_visit_node(root, check_bounds, &len);
pm_parser_free(parser);
pm_arena_free(arena);
return 0;
}
Building and running against libprism.a:
cc -Iinclude check.c build/libprism.a -o check && ./check
Output on the 24-byte input (0..24):
PM_CALL_NODE start=22 length=4294967286 (0xfffffff6) end=4294967308 > source_len=24
PM_BLOCK_NODE start=23 length=4294967285 (0xfffffff5) end=4294967308 > source_len=24
- Lingua principale
- C
- Stelle
- 1k
- Fork
- 202
- Merge medio
- 5h 55m
- PR unite (30g)
- 85
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/prism
-
Prism::Translation::Parser raises NoMethodError for a method with a &nil parameter and a bodyForse già presa @bbatsov l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Heredoc and outer-context recovery at recursion depth / stack budget limit causes location underflowAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 43/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 1/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Memory leak: "Add to Playlist" (`CMD_EVENT_ADD_TO_PLAYLIST`) never frees the playlist it loadsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Signed/unsigned mix in the EOCD backward scan rejects valid archives with a 65535-byte commentAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
area: recompiler area: runtime kind: bug preview-effort: small priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100