postgres.git / summary / log / commit / refs
commit e75feb28341ea49e9d41266906e701a4e3742e2e
Author: Andrew Dunstan <andrew@dunslane.net>
Date: Thu Apr 04 22:26:52 2013 +0000
First released in: 9.3.0
Fix off by one error in JSON extract path code.
Bug report by David Wheeler, diagnosis assistance from Tom Lane.
src/backend/utils/adt/jsonfuncs.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 63df1ac6777..73bcdf46b12 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -682,9 +682,13 @@ get_array_start(void *state)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot extract field from a non-object")));
- /* initialize array count for this nesting level */
+ /*
+ * initialize array count for this nesting level
+ * Note: the lex_level seen by array_start is one less than that seen by
+ * the elements of the array.
+ */
if (_state->search_type == JSON_SEARCH_PATH &&
- lex_level <= _state->npath)
+ lex_level < _state->npath)
_state->array_level_index[lex_level] = -1;
}
[parent: 48a2cd370e26]