couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [17/50] couch commit: updated refs/heads/windsor-merge to 6e60cbe
Date Thu, 07 Aug 2014 15:37:39 GMT
Remember to protect field access on old headers

couch_db_header:get_field/2 is not guranteed to be called only on valid
db_header records so return undefined for any field beyond the given
tuple.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/d34d7960
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/d34d7960
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/d34d7960

Branch: refs/heads/windsor-merge
Commit: d34d7960d2d0669192d4d8a35197dc0d12e274a9
Parents: f77e694
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Fri Jun 14 14:55:34 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Aug 5 16:19:01 2014 +0100

----------------------------------------------------------------------
 src/couch_db_header.erl | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/d34d7960/src/couch_db_header.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_header.erl b/src/couch_db_header.erl
index ff771d1..1d743ef 100644
--- a/src/couch_db_header.erl
+++ b/src/couch_db_header.erl
@@ -155,7 +155,11 @@ epochs(Header) ->
 
 
 get_field(Header, Field) ->
-    element(index(Field), Header).
+    Idx = index(Field),
+    case Idx > tuple_size(Header) of
+        true -> undefined;
+        false -> element(index(Field), Header)
+    end.
 
 
 set_field(Header, Field, Value) ->
@@ -343,4 +347,14 @@ upgrade_epochs_test() ->
     ?assertEqual(OwnedEpochs, epochs(ResetHeader)).
 
 
+get_uuid_from_old_header_test() ->
+    Vsn5Header = mk_header(5),
+    ?assertEqual(undefined, uuid(Vsn5Header)).
+
+
+get_epochs_from_old_header_test() ->
+    Vsn5Header = mk_header(5),
+    ?assertEqual(undefined, epochs(Vsn5Header)).
+
+
 -endif.


Mime
View raw message