awk: an invalid (or unsupported) regex panics

Aperta
#174 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
awk, rust
Ambito
backend, cli

Direzione di ricerca

Start at interpreter/src/vm/types.rs:368, where the panic occurs, and trace how regex compilation errors reach the awk interpreter. Check the regex handling and existing CLI tests for the two cases in the issue. Done means malformed regexes report an error without panicking, while [!---] matches - and the reported tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug crash gnu-compat good first issue

When a regex literal does not compile, uutils awk panics instead of reporting
an error. This also happens for a bracket expression GNU accepts, [a---z]
(a range ending at -).

Reproduction

Rust (incorrect)

$ ./target/release/awk 'BEGIN { print ("x" ~ /[x/) }'
thread 'main' panicked at interpreter/src/vm/types.rs:368:80:
called `Result::unwrap()` on an `Err` value: UnbalancedBracket("unbalanced [")
# Exit code: 2

$ ./target/release/awk 'BEGIN { print ("-" ~ /[a---z]/) }'
thread 'main' panicked at interpreter/src/vm/types.rs:368:80:
called `Result::unwrap()` on an `Err` value: InvalidEndpoint("invalid range endpoint")

GNU (correct)

$ gawk 'BEGIN { print ("x" ~ /[x/) }'
gawk: cmd. line:1: BEGIN { print ("x" ~ /[x/) }
gawk: cmd. line:1:                       ^ unterminated regexp
# Exit code: 1

$ gawk 'BEGIN { print ("-" ~ /[a---z]/) }'
1

Test

#[test]
fn unbalanced_bracket_regex_is_an_error() {
    ucmd()
        .arg("BEGIN { if (\"q\" ~ /[q/) print 1 }")
        .fails_with_code(1)
        .stderr_does_not_contain("panicked");
}

#[test]
fn bracket_range_ending_in_dash() {
    ucmd()
        .arg("BEGIN { print (\"-\" ~ /[!---]/) }")
        .succeeds()
        .stdout_only("1\n");
}

Exposed by the GNU awk test suite: regexpbad, regex3minus.

Lingua principale
Rust
Stelle
31
Fork
13
Merge medio
23h 42m
PR unite (30g)
29

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/awk

Tutte le issue di uutils/awk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.