diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-07-03 17:42:54 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-07-03 17:42:54 +0200 |
commit | 4aac65c4b8f2d8415ca8d9d8449e0158e0ff1e9c (patch) | |
tree | 609b2e2349371006e37c9112c9ceebbbffe45950 /src/file.c | |
parent | c23d58aaec79938f29cdac8336d4dcd46cc346ab (diff) | |
download | blogc-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.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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); } |