You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:12:18 UTC
[47/50] [abbrv] git commit: Prevent segfaults on unterminated strings
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.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/e8121ad5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/e8121ad5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/e8121ad5
Branch: refs/heads/import
Commit: e8121ad5add210e83e8739402e34bd182afc10c0
Parents: bf82761
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jun 5 10:02:30 2013 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jun 5 10:04:05 2013 -0500
----------------------------------------------------------------------
c_src/decoder.c | 9 +++++----
test/004-strings.t | 3 ++-
2 files changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/e8121ad5/c_src/decoder.c
----------------------------------------------------------------------
diff --git a/c_src/decoder.c b/c_src/decoder.c
index 604a310..fc892da 100644
--- a/c_src/decoder.c
+++ b/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;
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/e8121ad5/test/004-strings.t
----------------------------------------------------------------------
diff --git a/test/004-strings.t b/test/004-strings.t
index 30fa0d5..d5e5161 100755
--- a/test/004-strings.t
+++ b/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\"">>,