| 27 | #include <sys/stat.h> |
| 28 | |
| 29 | static char *security_read_file(const char *path) { |
| 30 | FILE *file = fopen(path, "rb"); |
| 31 | if (!file || fseek(file, 0, SEEK_END) != 0) { |
| 32 | if (file) |
| 33 | fclose(file); |
| 34 | return NULL; |
| 35 | } |
| 36 | long size = ftell(file); |
| 37 | if (size < 0 || fseek(file, 0, SEEK_SET) != 0) { |
| 38 | fclose(file); |
| 39 | return NULL; |
| 40 | } |
| 41 | char *content = (char *)malloc((size_t)size + 1U); |
| 42 | if (!content || fread(content, 1U, (size_t)size, file) != (size_t)size) { |
| 43 | free(content); |
| 44 | fclose(file); |
| 45 | return NULL; |
| 46 | } |
| 47 | content[size] = '\0'; |
| 48 | fclose(file); |
| 49 | return content; |
| 50 | } |
| 51 | |
| 52 | static void security_normalize_crlf(char *content) { |
| 53 | if (!content) { |
no outgoing calls
no test coverage detected