From f2ea3154a742238f0b9943bb58efd0627ffda3e8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 24 Nov 2022 16:40:49 -0500 Subject: Gracefully handle bad characters in Turtle blank node syntax --- NEWS | 3 ++- src/attributes.h | 6 ++++++ src/n3.c | 4 +++- src/reader.h | 3 ++- test/bad/bad-blank-syntax.ttl | 1 + test/bad/manifest.ttl | 6 ++++++ 6 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 test/bad/bad-blank-syntax.ttl diff --git a/NEWS b/NEWS index 19de1273..06790a11 100644 --- a/NEWS +++ b/NEWS @@ -3,11 +3,12 @@ serd (0.30.17) unstable; urgency=medium * Add Windows path separator support to serd_node_new_file_uri() * Fix crash when trying to read chunks without starting * Fix hang when skipping an error at EOF when lax parsing + * Gracefully handle bad characters in Turtle blank node syntax * Gracefully handle bad characters in Turtle datatype syntax * Override pkg-config dependency within meson * Test header for warnings more strictly - -- David Robillard Thu, 24 Nov 2022 20:51:55 +0000 + -- David Robillard Thu, 24 Nov 2022 21:05:52 +0000 serd (0.30.16) stable; urgency=medium diff --git a/src/attributes.h b/src/attributes.h index 25eb91d0..502634b0 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -10,4 +10,10 @@ # define SERD_MALLOC_FUNC #endif +#ifdef __GNUC__ +# define SERD_NODISCARD __attribute__((warn_unused_result)) +#else +# define SERD_NODISCARD +#endif + #endif // SERD_ATTRIBUTES_H diff --git a/src/n3.c b/src/n3.c index bffc423b..09e6792b 100644 --- a/src/n3.c +++ b/src/n3.c @@ -997,7 +997,9 @@ read_BLANK_NODE_LABEL(SerdReader* const reader, bool* const ate_dot) { eat_byte_safe(reader, '_'); - eat_byte_check(reader, ':'); + if (!eat_byte_check(reader, ':')) { + return SERD_ERR_BAD_SYNTAX; + } const Ref ref = *dest = push_node(reader, diff --git a/src/reader.h b/src/reader.h index 689eeecb..cccaa8a9 100644 --- a/src/reader.h +++ b/src/reader.h @@ -4,6 +4,7 @@ #ifndef SERD_READER_H #define SERD_READER_H +#include "attributes.h" #include "byte_source.h" #include "stack.h" @@ -131,7 +132,7 @@ eat_byte_safe(SerdReader* reader, const int byte) return c; } -static inline int +static inline int SERD_NODISCARD eat_byte_check(SerdReader* reader, const int byte) { const int c = peek_byte(reader); diff --git a/test/bad/bad-blank-syntax.ttl b/test/bad/bad-blank-syntax.ttl new file mode 100644 index 00000000..6c7117a2 --- /dev/null +++ b/test/bad/bad-blank-syntax.ttl @@ -0,0 +1 @@ + _|invalid . diff --git a/test/bad/manifest.ttl b/test/bad/manifest.ttl index 0f4f1338..05bcc69d 100644 --- a/test/bad/manifest.ttl +++ b/test/bad/manifest.ttl @@ -24,6 +24,7 @@ <#bad-14> <#bad-base> <#bad-blank> + <#bad-blank-syntax> <#bad-bom> <#bad-char-in-local> <#bad-char-in-prefix> @@ -166,6 +167,11 @@ mf:name "bad-blank" ; mf:action . +<#bad-blank-syntax> + rdf:type rdft:TestTurtleNegativeSyntax ; + mf:name "bad-blank-syntax" ; + mf:action . + <#bad-bom> rdf:type rdft:TestTurtleNegativeSyntax ; mf:name "bad-bom" ; -- cgit v1.2.1