summaryrefslogtreecommitdiff
path: root/contrib/hstore/hstore_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/hstore/hstore_io.c')
-rw-r--r--contrib/hstore/hstore_io.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index e01cb4e7599..08fc32e5099 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -182,7 +182,7 @@ parse_hstore(HSParser * state)
state->pairs = (Pairs *) repalloc(state->pairs, sizeof(Pairs) * state->plen);
}
state->pairs[state->pcur].key = state->word;
- state->pairs[state->pcur].keylen = state->cur - state->word;
+ state->pairs[state->pcur].keylen = hstoreCheckKeyLen(state->cur - state->word);
state->pairs[state->pcur].val = NULL;
state->word = NULL;
st = WEQ;
@@ -222,7 +222,7 @@ parse_hstore(HSParser * state)
if (!get_val(state, true, &escaped))
elog(ERROR, "Unexpected end of string");
state->pairs[state->pcur].val = state->word;
- state->pairs[state->pcur].vallen = state->cur - state->word;
+ state->pairs[state->pcur].vallen = hstoreCheckValLen(state->cur - state->word);
state->pairs[state->pcur].isnull = false;
state->pairs[state->pcur].needfree = true;
if (state->cur - state->word == 4 && !escaped)
@@ -341,6 +341,27 @@ freeHSParse(HSParser * state)
pfree(state->pairs);
}
+size_t
+hstoreCheckKeyLen(size_t len)
+{
+ if (len > HSTORE_MAX_KEY_LEN)
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
+ errmsg("string too long for hstore key")));
+ return len;
+}
+
+size_t
+hstoreCheckValLen(size_t len)
+{
+ if (len > HSTORE_MAX_VALUE_LEN)
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
+ errmsg("string too long for hstore value")));
+ return len;
+}
+
+
PG_FUNCTION_INFO_V1(hstore_in);
Datum hstore_in(PG_FUNCTION_ARGS);
Datum