From 4aac65c4b8f2d8415ca8d9d8449e0158e0ff1e9c Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 3 Jul 2016 17:42:54 +0200 Subject: blogc: added utf8 validation --- src/file.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/file.c') diff --git a/src/file.c b/src/file.c index f784d93..7171f31 100644 --- a/src/file.c +++ b/src/file.c @@ -16,6 +16,7 @@ #include #include "file.h" #include "error.h" +#include "utf8.h" #include "utils.h" // this would belong to loader.c, but we need it in a separated file to be @@ -47,6 +48,14 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) sb_string_append_len(str, buffer, read_len); } fclose(fp); + + if (!blogc_utf8_validate_str(str)) { + *err = blogc_error_new_printf(BLOGC_ERROR_LOADER, + "File content is not valid UTF-8: %s", path); + sb_string_free(str, true); + return NULL; + } + return sb_string_free(str, false); } -- cgit v1.2.3-18-g5258