浏览代码

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) {
*value = enif_make_sub_binary(d->env, d->arg, st, (d->i - st - 1));
return 1;

+ 2
- 1
test/004-strings.t 查看文件

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

正在加载...
取消
保存