aboutsummaryrefslogtreecommitdiffstats
path: root/src/n3.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-18 23:52:15 +0200
committerDavid Robillard <d@drobilla.net>2018-04-18 23:52:15 +0200
commit2faabcaf2760a4c909d4be2f95057711e5eb9e23 (patch)
treec6bfef83db9cfb0ec468cd2ac30cd21988be64cf /src/n3.c
parent9bd9baa166b2dca7c3df225938e6c2d3eae58d8d (diff)
downloadserd-2faabcaf2760a4c909d4be2f95057711e5eb9e23.tar.gz
serd-2faabcaf2760a4c909d4be2f95057711e5eb9e23.tar.bz2
serd-2faabcaf2760a4c909d4be2f95057711e5eb9e23.zip
Fix potential memory errors when the reader stack grows
This fixes possible segfaults for inputs that push a lot to the stack, like files with deeply nested or very large nodes.
Diffstat (limited to 'src/n3.c')
-rw-r--r--src/n3.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/n3.c b/src/n3.c
index b35031bb..b97b0cd0 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -824,9 +824,9 @@ read_verb(SerdReader* reader, Ref* dest)
"a", produce that instead.
*/
*dest = push_node(reader, SERD_CURIE, "", 0);
- SerdNode* node = deref(reader, *dest);
const SerdStatus st = read_PN_PREFIX(reader, *dest);
bool ate_dot = false;
+ SerdNode* node = deref(reader, *dest);
if (!st && node->n_bytes == 1 && node->buf[0] == 'a' &&
is_token_end(peek_byte(reader))) {
pop_node(reader, *dest);
@@ -1007,8 +1007,9 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
/* Either a boolean literal, or a qname. Read the prefix first, and if
it is in fact a "true" or "false" literal, produce that instead.
*/
- node = deref(reader, o = push_node(reader, SERD_CURIE, "", 0));
+ o = push_node(reader, SERD_CURIE, "", 0);
while (!read_PN_CHARS_BASE(reader, o)) {}
+ node = deref(reader, o);
if ((node->n_bytes == 4 && !memcmp(node->buf, "true", 4)) ||
(node->n_bytes == 5 && !memcmp(node->buf, "false", 5))) {
node->type = SERD_LITERAL;