g_ptr_array_free (arch->files, TRUE);
}
-static GString *
+static bool
rspamd_archive_file_try_utf (struct rspamd_task *task,
- const gchar *in, gsize inlen)
+ struct rspamd_archive_file *fentry,
+ const gchar *in, gsize inlen)
{
const gchar *charset = NULL, *p, *end;
GString *res;
if (conv == NULL) {
msg_info_task ("cannot open converter for %s: %s",
charset, u_errorName (uc_err));
+ fentry->flags |= RSPAMD_ARCHIVE_FILE_OBFUSCATED;
+ fentry->fname = g_string_new_len(in, inlen);
- return NULL;
+ return false;
}
tmp = g_malloc (sizeof (*tmp) * (inlen + 1));
charset, u_errorName (uc_err));
g_free (tmp);
+ fentry->flags |= RSPAMD_ARCHIVE_FILE_OBFUSCATED;
+ fentry->fname = g_string_new_len(in, inlen);
+
return NULL;
}
charset, u_errorName (uc_err));
g_free (tmp);
g_string_free (res, TRUE);
+ fentry->flags |= RSPAMD_ARCHIVE_FILE_OBFUSCATED;
+ fentry->fname = g_string_new_len(in, inlen);
return NULL;
}
+ int i = 0;
+
+ while (i < r) {
+ UChar32 uc;
+
+ U16_NEXT(tmp, i, r, uc);
+
+ if (IS_ZERO_WIDTH_SPACE(uc) || u_iscntrl(uc)) {
+ msg_info_task("control character in archive name found: %d", uc);
+ fentry->flags |= RSPAMD_ARCHIVE_FILE_OBFUSCATED;
+ break;
+ }
+ }
+
g_free (tmp);
res->len = r;
msg_debug_archive ("converted from %s to UTF-8 inlen: %z, outlen: %d",
charset, inlen, r);
+ fentry->fname = res;
}
else {
/* Convert unsafe characters to '?' */
}
else {
g_string_append_c (res, '?');
+ fentry->flags |= RSPAMD_ARCHIVE_FILE_OBFUSCATED;
}
p ++;
}
+ fentry->fname = res;
}
- return res;
+ return true;
}
static void
}
f = g_malloc0 (sizeof (*f));
- f->fname = rspamd_archive_file_try_utf (task,
- cd + cd_basic_len, fname_len);
+ rspamd_archive_file_try_utf (task, f, cd + cd_basic_len, fname_len);
+
f->compressed_size = comp_size;
f->uncompressed_size = uncomp_size;
}
if (f->fname) {
+ if (f->flags & RSPAMD_ARCHIVE_FILE_OBFUSCATED) {
+ arch->flags |= RSPAMD_ARCHIVE_HAS_OBFUSCATED_FILES;
+ }
+
g_ptr_array_add (arch->files, f);
msg_debug_archive ("found file in zip archive: %v", f->fname);
}
if (tmp != NULL) {
/* Just use ASCII version */
- f->fname = rspamd_archive_file_try_utf (task, p, tmp - p);
+ rspamd_archive_file_try_utf (task, f, p, tmp - p);
msg_debug_archive ("found ascii filename in rarv4 archive: %v",
f->fname);
}
else {
/* We have UTF8 filename, use it as is */
- f->fname = rspamd_archive_file_try_utf (task, p, fname_len);
+ rspamd_archive_file_try_utf (task, f, p, fname_len);
msg_debug_archive ("found utf filename in rarv4 archive: %v",
f->fname);
}
}
else {
- f->fname = rspamd_archive_file_try_utf (task, p, fname_len);
+ rspamd_archive_file_try_utf (task, f, p, fname_len);
msg_debug_archive ("found ascii (old) filename in rarv4 archive: %v",
f->fname);
}
}
if (f->fname) {
+ if (f->flags & RSPAMD_ARCHIVE_FILE_OBFUSCATED) {
+ arch->flags |= RSPAMD_ARCHIVE_HAS_OBFUSCATED_FILES;
+ }
g_ptr_array_add (arch->files, f);
}
else {
f = g_malloc0 (sizeof (*f));
f->uncompressed_size = uncomp_sz;
f->compressed_size = comp_sz;
- f->fname = rspamd_archive_file_try_utf (task, p, fname_len);
+ rspamd_archive_file_try_utf (task, f, p, fname_len);
if (f->fname) {
msg_debug_archive ("added rarv5 file: %v", f->fname);
g_ptr_array_add (arch->files, f);
+ if (f->flags & RSPAMD_ARCHIVE_FILE_OBFUSCATED) {
+ arch->flags |= RSPAMD_ARCHIVE_HAS_OBFUSCATED_FILES;
+ }
}
else {
g_free (f);
struct rspamd_archive_file *f;
f = g_malloc0 (sizeof (*f));
- f->fname = rspamd_archive_file_try_utf (task, fname_start,
- p - fname_start);
+
+ rspamd_archive_file_try_utf (task, f,
+ fname_start, p - fname_start);
if (f->fname) {
g_ptr_array_add (arch->files, f);
+
+ if (f->flags & RSPAMD_ARCHIVE_FILE_OBFUSCATED) {
+ arch->flags |= RSPAMD_ARCHIVE_HAS_OBFUSCATED_FILES;
+ }
}
else {
/* Invalid filename, skip */