diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-18 18:56:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-18 18:56:33 +0000 |
commit | 14c13854d3cae9d93c3d148be30fb72f1eaffe55 (patch) | |
tree | 7b1a3e41b75490fac4d45722c90a1847543c6796 /src/libmime/archives.c | |
parent | 6b2b4167187fee09365271cca182866ecb029af3 (diff) | |
download | rspamd-14c13854d3cae9d93c3d148be30fb72f1eaffe55.tar.gz rspamd-14c13854d3cae9d93c3d148be30fb72f1eaffe55.zip |
[Rework] Further types conversion (no functional changes)
Diffstat (limited to 'src/libmime/archives.c')
-rw-r--r-- | src/libmime/archives.c | 256 |
1 files changed, 128 insertions, 128 deletions
diff --git a/src/libmime/archives.c b/src/libmime/archives.c index 7f77cf591..c40c0e88a 100644 --- a/src/libmime/archives.c +++ b/src/libmime/archives.c @@ -39,7 +39,7 @@ rspamd_archive_dtor(gpointer p) { struct rspamd_archive *arch = p; struct rspamd_archive_file *f; - guint i; + unsigned int i; for (i = 0; i < arch->files->len; i++) { f = g_ptr_array_index(arch->files, i); @@ -58,9 +58,9 @@ static bool rspamd_archive_file_try_utf(struct rspamd_task *task, struct rspamd_archive *arch, struct rspamd_archive_file *fentry, - const gchar *in, gsize inlen) + const char *in, gsize inlen) { - const gchar *charset = NULL, *p, *end; + const char *charset = NULL, *p, *end; GString *res; charset = rspamd_mime_charset_find_by_content(in, inlen, TRUE); @@ -173,12 +173,12 @@ static void rspamd_archive_process_zip(struct rspamd_task *task, struct rspamd_mime_part *part) { - const guchar *p, *start, *end, *eocd = NULL, *cd; + const unsigned char *p, *start, *end, *eocd = NULL, *cd; const uint32_t eocd_magic = 0x06054b50, cd_basic_len = 46; - const guchar cd_magic[] = {0x50, 0x4b, 0x01, 0x02}; - const guint max_processed = 1024; + const unsigned char cd_magic[] = {0x50, 0x4b, 0x01, 0x02}; + const unsigned int max_processed = 1024; uint32_t cd_offset, cd_size, comp_size, uncomp_size, processed = 0; - guint16 extra_len, fname_len, comment_len; + uint16_t extra_len, fname_len, comment_len; struct rspamd_archive *arch; struct rspamd_archive_file *f = NULL; @@ -233,7 +233,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, cd_offset = GUINT32_FROM_LE(cd_offset); /* We need to check sanity as well */ - if (cd_offset + cd_size > (guint) (eocd - start)) { + if (cd_offset + cd_size > (unsigned int) (eocd - start)) { msg_info_task("zip archive is invalid (bad size/offset for CD)"); return; @@ -251,7 +251,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, arch); while (cd < start + cd_offset + cd_size) { - guint16 flags; + uint16_t flags; /* Read central directory record */ if (eocd - cd < cd_basic_len || @@ -261,7 +261,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, return; } - memcpy(&flags, cd + 8, sizeof(guint16)); + memcpy(&flags, cd + 8, sizeof(uint16_t)); flags = GUINT16_FROM_LE(flags); memcpy(&comp_size, cd + 20, sizeof(uint32_t)); comp_size = GUINT32_FROM_LE(comp_size); @@ -305,22 +305,22 @@ rspamd_archive_process_zip(struct rspamd_task *task, } /* Process extra fields */ - const guchar *extra = cd + fname_len + cd_basic_len; + const unsigned char *extra = cd + fname_len + cd_basic_len; p = extra; - while (p + sizeof(guint16) * 2 < extra + extra_len) { - guint16 hid, hlen; + while (p + sizeof(uint16_t) * 2 < extra + extra_len) { + uint16_t hid, hlen; - memcpy(&hid, p, sizeof(guint16)); + memcpy(&hid, p, sizeof(uint16_t)); hid = GUINT16_FROM_LE(hid); - memcpy(&hlen, p + sizeof(guint16), sizeof(guint16)); + memcpy(&hlen, p + sizeof(uint16_t), sizeof(uint16_t)); hlen = GUINT16_FROM_LE(hlen); if (hid == 0x0017) { f->flags |= RSPAMD_ARCHIVE_FILE_ENCRYPTED; } - p += hlen + sizeof(guint16) * 2; + p += hlen + sizeof(uint16_t) * 2; } cd += fname_len + comment_len + extra_len + cd_basic_len; @@ -332,8 +332,8 @@ rspamd_archive_process_zip(struct rspamd_task *task, arch->size = part->parsed_data.len; } -static inline gint -rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res) +static inline int +rspamd_archive_rar_read_vint(const unsigned char *start, gsize remain, uint64_t *res) { /* * From http://www.rarlab.com/technote.htm: @@ -345,8 +345,8 @@ rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res) * continuation flag. Second byte, if present, contains next 7 bits and so on. */ uint64_t t = 0; - guint shift = 0; - const guchar *p = start; + unsigned int shift = 0; + const unsigned char *p = start; while (remain > 0 && shift <= 57) { if (*p & 0x80) { @@ -410,31 +410,31 @@ rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res) #define RAR_READ_UINT16(n) \ do { \ - if (end - p < (glong) sizeof(guint16)) { \ + if (end - p < (glong) sizeof(uint16_t)) { \ msg_debug_archive("rar archive is invalid (bad int16)"); \ return; \ } \ n = p[0] + (p[1] << 8); \ - p += sizeof(guint16); \ + p += sizeof(uint16_t); \ } while (0) -#define RAR_READ_UINT32(n) \ - do { \ - if (end - p < (glong) sizeof(uint32_t)) { \ - msg_debug_archive("rar archive is invalid (bad int32)"); \ - return; \ - } \ - n = (guint) p[0] + ((guint) p[1] << 8) + ((guint) p[2] << 16) + ((guint) p[3] << 24); \ - p += sizeof(uint32_t); \ +#define RAR_READ_UINT32(n) \ + do { \ + if (end - p < (glong) sizeof(uint32_t)) { \ + msg_debug_archive("rar archive is invalid (bad int32)"); \ + return; \ + } \ + n = (unsigned int) p[0] + ((unsigned int) p[1] << 8) + ((unsigned int) p[2] << 16) + ((unsigned int) p[3] << 24); \ + p += sizeof(uint32_t); \ } while (0) static void -rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, - const guchar *end, struct rspamd_mime_part *part) +rspamd_archive_process_rar_v4(struct rspamd_task *task, const unsigned char *start, + const unsigned char *end, struct rspamd_mime_part *part) { - const guchar *p = start, *start_section; - guint8 type; - guint flags; + const unsigned char *p = start, *start_section; + uint8_t type; + unsigned int flags; uint64_t sz, comp_sz = 0, uncomp_sz = 0; struct rspamd_archive *arch; struct rspamd_archive_file *f; @@ -451,7 +451,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, while (p < end) { /* Crc16 */ start_section = p; - RAR_SKIP_BYTES(sizeof(guint16)); + RAR_SKIP_BYTES(sizeof(uint16_t)); type = *p; p++; RAR_READ_UINT16(flags); @@ -484,7 +484,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, } if (type == 0x74) { - guint fname_len; + unsigned int fname_len; /* File header */ /* Uncompressed size */ @@ -519,7 +519,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, if (flags & 0x200) { /* We have unicode + normal version */ - guchar *tmp; + unsigned char *tmp; tmp = memchr(p, '\0', fname_len); @@ -574,16 +574,16 @@ static void rspamd_archive_process_rar(struct rspamd_task *task, struct rspamd_mime_part *part) { - const guchar *p, *end, *section_start; - const guchar rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00}, - rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00}; - const guint rar_encrypted_header = 4, rar_main_header = 1, - rar_file_header = 2; + const unsigned char *p, *end, *section_start; + const unsigned char rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00}, + rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00}; + const unsigned int rar_encrypted_header = 4, rar_main_header = 1, + rar_file_header = 2; uint64_t vint, sz, comp_sz = 0, uncomp_sz = 0, flags = 0, type = 0, extra_sz = 0; struct rspamd_archive *arch; struct rspamd_archive_file *f; - gint r; + int r; p = part->parsed_data.begin; end = p + part->parsed_data.len; @@ -764,10 +764,10 @@ rspamd_archive_process_rar(struct rspamd_task *task, if (f && has_extra && extra_sz > 0 && p + fname_len + extra_sz < end) { /* Try to find encryption record in extra field */ - const guchar *ex = p + fname_len; + const unsigned char *ex = p + fname_len; while (ex < p + extra_sz) { - const guchar *t; + const unsigned char *t; int64_t cur_sz = 0, sec_type = 0; r = rspamd_archive_rar_read_vint(ex, extra_sz, &cur_sz); @@ -807,8 +807,8 @@ end: arch->size = part->parsed_data.len; } -static inline gint -rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) +static inline int +rspamd_archive_7zip_read_vint(const unsigned char *start, gsize remain, uint64_t *res) { /* * REAL_UINT64 means real UINT64. @@ -825,7 +825,7 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) * 11111110 BYTE y[7] : y * 11111111 BYTE y[8] : y */ - guchar t; + unsigned char t; if (remain == 0) { return -1; @@ -847,8 +847,8 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) } } else { - gint cur_bit = 6, intlen = 1; - const guchar bmask = 0xFF; + int cur_bit = 6, intlen = 1; + const unsigned char bmask = 0xFF; uint64_t tgt; while (cur_bit > 0) { @@ -904,15 +904,15 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) n = GUINT64_FROM_LE(n); \ p += sizeof(uint64_t); \ } while (0) -#define SZ_SKIP_BYTES(n) \ - do { \ - if (end - p >= (n)) { \ - p += (n); \ - } \ - else { \ - msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (gint) (n), (gint) (end - p), G_STRLOC); \ - return NULL; \ - } \ +#define SZ_SKIP_BYTES(n) \ + do { \ + if (end - p >= (n)) { \ + p += (n); \ + } \ + else { \ + msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (int) (n), (int) (end - p), G_STRLOC); \ + return NULL; \ + } \ } while (0) enum rspamd_7zip_header_mark { @@ -953,11 +953,11 @@ enum rspamd_7zip_header_mark { ((codec_id) == _7Z_CRYPTO_RAR_29) || \ ((codec_id) == _7Z_CRYPTO_AES_256_SHA_256)) -static const guchar * +static const unsigned char * rspamd_7zip_read_bits(struct rspamd_task *task, - const guchar *p, const guchar *end, - struct rspamd_archive *arch, guint nbits, - guint *pbits_set) + const unsigned char *p, const unsigned char *end, + struct rspamd_archive *arch, unsigned int nbits, + unsigned int *pbits_set) { unsigned mask = 0, avail = 0, i; gboolean bit_set = 0; @@ -981,16 +981,16 @@ rspamd_7zip_read_bits(struct rspamd_task *task, return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_digest(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, uint64_t num_streams, - guint *pdigest_read) + unsigned int *pdigest_read) { - guchar all_defined = *p; + unsigned char all_defined = *p; uint64_t i; - guint num_defined = 0; + unsigned int num_defined = 0; /* * BYTE AllAreDefined * if (AllAreDefined == 0) @@ -1029,14 +1029,14 @@ rspamd_7zip_read_digest(struct rspamd_task *task, return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_pack_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { uint64_t pack_pos = 0, pack_streams = 0, i, cur_sz; - guint num_digests = 0; - guchar t; + unsigned int num_digests = 0; + unsigned char t; /* * UINT64 PackPos * UINT64 NumPackStreams @@ -1089,10 +1089,10 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_folder(struct rspamd_task *task, - const guchar *p, const guchar *end, - struct rspamd_archive *arch, guint *pnstreams, guint *ndigests) + const unsigned char *p, const unsigned char *end, + struct rspamd_archive *arch, unsigned int *pnstreams, unsigned int *ndigests) { uint64_t ncoders = 0, i, j, noutstreams = 0, ninstreams = 0; @@ -1100,7 +1100,7 @@ rspamd_7zip_read_folder(struct rspamd_task *task, for (i = 0; i < ncoders && p != NULL && p < end; i++) { uint64_t sz, tmp; - guchar t; + unsigned char t; /* * BYTE * { @@ -1189,15 +1189,15 @@ rspamd_7zip_read_folder(struct rspamd_task *task, return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_coders_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, - guint *pnum_folders, guint *pnum_nodigest) + unsigned int *pnum_folders, unsigned int *pnum_nodigest) { uint64_t num_folders = 0, i, tmp; - guchar t; - guint *folder_nstreams = NULL, num_digests = 0, digests_read = 0; + unsigned char t; + unsigned int *folder_nstreams = NULL, num_digests = 0, digests_read = 0; while (p != NULL && p < end) { /* @@ -1259,11 +1259,11 @@ rspamd_7zip_read_coders_info(struct rspamd_task *task, case kCodersUnPackSize: for (i = 0; i < num_folders && p != NULL && p < end; i++) { if (folder_nstreams) { - for (guint j = 0; j < folder_nstreams[i]; j++) { + for (unsigned int j = 0; j < folder_nstreams[i]; j++) { SZ_READ_VINT(tmp); /* Unpacked size */ msg_debug_archive("7zip: unpacked size " "(folder=%d, stream=%d) = %L", - (gint) i, j, tmp); + (int) i, j, tmp); } } else { @@ -1315,14 +1315,14 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_substreams_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, - guint num_folders, guint num_nodigest) + unsigned int num_folders, unsigned int num_nodigest) { - guchar t; - guint i; + unsigned char t; + unsigned int i; uint64_t *folder_nstreams; if (num_folders > 8192) { @@ -1380,7 +1380,7 @@ rspamd_7zip_read_substreams_info(struct rspamd_task *task, * In fact, it is just absent in the real life... */ for (i = 0; i < num_folders; i++) { - for (guint j = 0; j < folder_nstreams[i]; j++) { + for (unsigned int j = 0; j < folder_nstreams[i]; j++) { uint64_t tmp; SZ_READ_VINT(tmp); /* Who cares indeed */ @@ -1402,13 +1402,13 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_main_streams_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { - guchar t; - guint num_folders = 0, unknown_digests = 0; + unsigned char t; + unsigned int num_folders = 0, unknown_digests = 0; while (p != NULL && p < end) { t = *p; @@ -1459,12 +1459,12 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_archive_props(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { - guchar proptype; + unsigned char proptype; uint64_t proplen; /* @@ -1501,18 +1501,18 @@ rspamd_7zip_read_archive_props(struct rspamd_task *task, } static GString * -rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p, - const guchar *end) +rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const unsigned char *p, + const unsigned char *end) { GString *res; goffset dest_pos = 0, src_pos = 0; - const gsize len = (end - p) / sizeof(guint16); - guint16 *up; + const gsize len = (end - p) / sizeof(uint16_t); + uint16_t *up; UChar32 wc; UBool is_error = 0; res = g_string_sized_new((end - p) * 3 / 2 + sizeof(wc) + 1); - up = (guint16 *) p; + up = (uint16_t *) p; while (src_pos < len) { U16_NEXT(up, src_pos, len, wc); @@ -1538,13 +1538,13 @@ rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p, return res; } -static const guchar * +static const unsigned char * rspamd_7zip_read_files_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { uint64_t nfiles = 0, sz, i; - guchar t, b; + unsigned char t, b; struct rspamd_archive_file *fentry; SZ_READ_VINT(nfiles); @@ -1592,7 +1592,7 @@ rspamd_7zip_read_files_info(struct rspamd_task *task, for (i = 0; i < nfiles; i++) { /* Zero terminated wchar_t: happy converting... */ /* First, find terminator */ - const guchar *fend = NULL, *tp = p; + const unsigned char *fend = NULL, *tp = p; GString *res; while (tp < end - 1) { @@ -1644,13 +1644,13 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_next_section(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, struct rspamd_mime_part *part) { - guchar t = *p; + unsigned char t = *p; SZ_SKIP_BYTES(1); @@ -1732,8 +1732,8 @@ rspamd_archive_process_7zip(struct rspamd_task *task, struct rspamd_mime_part *part) { struct rspamd_archive *arch; - const guchar *start, *p, *end; - const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; + const unsigned char *start, *p, *end; + const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; uint64_t section_offset = 0, section_length = 0; start = part->parsed_data.begin; @@ -1793,9 +1793,9 @@ rspamd_archive_process_gzip(struct rspamd_task *task, struct rspamd_mime_part *part) { struct rspamd_archive *arch; - const guchar *start, *p, *end; - const guchar gz_magic[] = {0x1F, 0x8B}; - guchar flags; + const unsigned char *start, *p, *end; + const unsigned char gz_magic[] = {0x1F, 0x8B}; + unsigned char flags; start = part->parsed_data.begin; p = start; @@ -1834,7 +1834,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, if (flags & (1u << 2)) { /* Optional section */ - guint16 optlen = 0; + uint16_t optlen = 0; RAR_READ_UINT16(optlen); @@ -1849,7 +1849,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, } /* Read file name */ - const guchar *fname_start = p; + const unsigned char *fname_start = p; while (p < end) { if (*p == '\0') { @@ -1889,7 +1889,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, /* Fallback, we need to extract file name from archive name if possible */ if (part->cd && part->cd->filename.len > 0) { - const gchar *dot_pos, *slash_pos; + const char *dot_pos, *slash_pos; dot_pos = rspamd_memrchr(part->cd->filename.begin, '.', part->cd->filename.len); @@ -1914,7 +1914,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, goto set; } else { - const gchar *fname_start = part->cd->filename.begin; + const char *fname_start = part->cd->filename.begin; f = g_malloc0(sizeof(*f)); @@ -1951,11 +1951,11 @@ set: } static gboolean -rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str, - const guchar *magic_start, gsize magic_len) +rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const char *str, + const unsigned char *magic_start, gsize magic_len) { struct rspamd_content_type *ct; - const gchar *p; + const char *p; rspamd_ftok_t srch, *fname; ct = part->ct; @@ -2024,12 +2024,12 @@ rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str, void rspamd_archives_process(struct rspamd_task *task) { - guint i; + unsigned int i; struct rspamd_mime_part *part; - const guchar rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; - const guchar zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; - const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; - const guchar gz_magic[] = {0x1F, 0x8B, 0x08}; + const unsigned char rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; + const unsigned char zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; + const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; + const unsigned char gz_magic[] = {0x1F, 0x8B, 0x08}; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) { @@ -2071,10 +2071,10 @@ void rspamd_archives_process(struct rspamd_task *task) } -const gchar * +const char * rspamd_archive_type_str(enum rspamd_archive_type type) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (type) { case RSPAMD_ARCHIVE_ZIP: |