Переглянути джерело

Prevent segfaults on unterminated strings

A single quote input was causing segfaults due to sneaking past the
string termination logic. This patch corrects that lapse in conditional
by only parsing strings where a closing quote was found. All other
strings are rejected as invalid.

Big thanks to Jean-Charles Campagne (@jccampagne) for reporting the
issue.
pull/44/head 0.8.4
Paul J. Davis 12 роки тому
джерело
коміт
e8121ad5ad
2 змінених файлів з 7 додано та 5 видалено
  1. +5
    -4
      c_src/decoder.c
  2. +2
    -1
      test/004-strings.t

+ 5
- 4
c_src/decoder.c Переглянути файл

@ -246,11 +246,12 @@ dec_string(Decoder* d, ERL_NIF_TERM* value)
} }
} }
parse:
if(d->p[d->i-1] != '\"') {
return 0;
}
// The goto above ensures that we only
// hit this when a string is not terminated
// correctly.
return 0;
parse:
if(!has_escape) { if(!has_escape) {
*value = enif_make_sub_binary(d->env, d->arg, st, (d->i - st - 1)); *value = enif_make_sub_binary(d->env, d->arg, st, (d->i - st - 1));
return 1; return 1;

+ 2
- 1
test/004-strings.t Переглянути файл

@ -6,7 +6,7 @@ main([]) ->
code:add_pathz("ebin"), code:add_pathz("ebin"),
code:add_pathz("test"), code:add_pathz("test"),
etap:plan(118),
etap:plan(119),
util:test_good(good()), util:test_good(good()),
util:test_good(uescaped(), [uescape]), util:test_good(uescaped(), [uescape]),
util:test_errors(errors()), util:test_errors(errors()),
@ -50,6 +50,7 @@ uescaped() ->
errors() -> errors() ->
[ [
"\"",
<<"\"foo">>, <<"\"foo">>,
<<"\"", 0, "\"">>, <<"\"", 0, "\"">>,
<<"\"\\g\"">>, <<"\"\\g\"">>,

Завантаження…
Відмінити
Зберегти