aboutsummaryrefslogtreecommitdiffstats
path: root/src/file.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-07-03 17:42:54 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-07-03 17:42:54 +0200
commit4aac65c4b8f2d8415ca8d9d8449e0158e0ff1e9c (patch)
tree609b2e2349371006e37c9112c9ceebbbffe45950 /src/file.c
parentc23d58aaec79938f29cdac8336d4dcd46cc346ab (diff)
downloadblogc-4aac65c4b8f2d8415ca8d9d8449e0158e0ff1e9c.tar.gz
blogc-4aac65c4b8f2d8415ca8d9d8449e0158e0ff1e9c.tar.bz2
blogc-4aac65c4b8f2d8415ca8d9d8449e0158e0ff1e9c.zip
blogc: added utf8 validation
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c9
1 files changed, 9 insertions, 0 deletions
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 <string.h>
#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);
}