diff options
author | David Robillard <d@drobilla.net> | 2018-11-17 21:01:59 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | b08b881585287e9c5e2f8ce50437643e02410ca1 (patch) | |
tree | 42c317bed50b64efd0651c316d48f077ad5d7f2e /test/test_overflow.c | |
parent | adcc570e4829c918798d3ccd7da9c8f5e0d137b6 (diff) | |
download | serd-b08b881585287e9c5e2f8ce50437643e02410ca1.tar.gz serd-b08b881585287e9c5e2f8ce50437643e02410ca1.tar.bz2 serd-b08b881585287e9c5e2f8ce50437643e02410ca1.zip |
Add stack overflow tests
Diffstat (limited to 'test/test_overflow.c')
-rw-r--r-- | test/test_overflow.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/test_overflow.c b/test/test_overflow.c new file mode 100644 index 00000000..5889a867 --- /dev/null +++ b/test/test_overflow.c @@ -0,0 +1,68 @@ +/* + Copyright 2018 David Robillard <d@drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#undef NDEBUG + +#include "serd/serd.h" + +#include <assert.h> +#include <stdio.h> + +static SerdStatus +test(SerdWorld* world, SerdSink* sink, const char* str, size_t stack_size) +{ + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, stack_size); + serd_reader_start_string(reader, str, NULL); + const SerdStatus st = serd_reader_read_document(reader); + serd_reader_free(reader); + return st; +} + +int +main(void) +{ + typedef struct { + const char* str; + size_t stack_size; + } Test; + + const Test tests[] = {{":s :p :%99 .", 338}, + {":s :p <http://", 336}, + {":s :p eg:foo", 337}, + {":s :p 1234", 307}, + {":s :p 1234", 338}, + {":s :p (1 2 3 4) .", 352}, + {"@prefix eg: <http://example.org> .", 239}, + {":s :p \"literal\"", 336}, + {":s :p \"verb\"", 275}, + {":s :p _:blank .", 307}, + {":s :p true .", 307}, + {":s :p true .", 341}, + {":s :p \"\"@en .", 339}, + {NULL, 0}}; + + SerdWorld* world = serd_world_new(); + SerdSink* sink = serd_sink_new(NULL, NULL, NULL); + + for (const Test* t = tests; t->str; ++t) { + const SerdStatus st = test(world, sink, t->str, t->stack_size); + assert(st == SERD_ERR_OVERFLOW); + } + + serd_sink_free(sink); + serd_world_free(world); + return 0; +} |