From 06f860fd95ba9f97e36416ad8fa3cdadba4f6259 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 17 Nov 2018 21:01:59 +0100 Subject: Add stack overflow tests --- tests/overflow_test.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/overflow_test.c (limited to 'tests/overflow_test.c') diff --git a/tests/overflow_test.c b/tests/overflow_test.c new file mode 100644 index 00000000..319a7e47 --- /dev/null +++ b/tests/overflow_test.c @@ -0,0 +1,73 @@ +/* + Copyright 2018 David Robillard + + 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. +*/ + +#include +#include +#include +#include + +#include "serd/serd.h" + +#include "test_utils.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(int argc, char** argv) +{ + typedef struct + { + const char* str; + size_t stack_size; + } Test; + + const Test tests[] = {{":s :p :%99 .", 338}, + {":s :p .", 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); + + for (const Test* t = tests; t->str; ++t) { + const SerdStatus st = test(world, sink, t->str, t->stack_size); + if (st != SERD_ERR_OVERFLOW) { + return serd_test_failure("%s, expected overflow\n", + serd_strerror(st)); + } + } + + serd_world_free(world); + return 0; +} -- cgit v1.2.1