Correcting types from int to cl_error_t where appropriate. Eliminating unused variables and referencing unused parameters to remove warnings.

pull/111/head
Micah Snyder 7 years ago
parent 8c37c1a081
commit 5f4f69102d
  1. 2
      clamd/clamd.c
  2. 2
      clamd/scanner.c
  3. 2
      clamscan/manager.c
  4. 2
      libclamav/filetypes.h
  5. 20
      libclamav/hwp.c
  6. 7
      libclamav/lzw/lzwdec.c
  7. 18
      libclamav/matcher-ac.c
  8. 18
      libclamav/matcher-ac.h
  9. 19
      libclamav/matcher-bm.c
  10. 8
      libclamav/matcher-bm.h
  11. 3
      libclamav/matcher-byte-comp.c
  12. 18
      libclamav/matcher-pcre.c
  13. 8
      libclamav/matcher-pcre.h
  14. 30
      libclamav/matcher.c
  15. 16
      libclamav/matcher.h
  16. 4
      libclamav/mbox.c
  17. 2
      libclamav/msdoc.c
  18. 4
      libclamav/msxml.c
  19. 2
      libclamav/msxml.h
  20. 2
      libclamav/others.c
  21. 2
      libclamav/others.h
  22. 1
      libclamav/others_common.c
  23. 4
      libclamav/pdfdecode.c
  24. 4
      libclamav/phish_whitelist.c
  25. 4
      libclamav/phish_whitelist.h
  26. 22
      libclamav/phishcheck.c
  27. 4
      libclamav/phishcheck.h
  28. 80
      libclamav/readdb.c
  29. 10
      libclamav/readdb.h
  30. 176
      libclamav/regex_list.c
  31. 10
      libclamav/regex_list.h
  32. 10
      libclamav/regex_pcre.c
  33. 8
      libclamav/regex_pcre.h
  34. 26
      libclamav/regex_suffix.c
  35. 2
      libclamav/regex_suffix.h
  36. 5
      libclamav/scanners.c
  37. 1
      libclamav/unzip.c
  38. 2
      libclamav/yara_grammar.y
  39. 2
      libclamav/yara_lexer.l
  40. 37
      libclamav/yara_parser.c
  41. 11
      shared/idmef_logging.c
  42. 4
      shared/optparser.c
  43. 8
      sigtool/sigtool.c

@ -596,8 +596,6 @@ int main(int argc, char **argv)
}
if (tcpsock || num_fd > 0) {
int *t;
opt = optget(opts, "TCPAddr");
if (opt->enabled) {
int breakout = 0;

@ -110,6 +110,8 @@ void clamd_virus_found_cb(int fd, const char *virname, void *ctx)
struct scan_cb_data *d = c->scandata;
const char *fname;
UNUSEDPARAM(fd);
if (d == NULL)
return;
if (!(d->options->general & CL_SCAN_GENERAL_ALLMATCHES) && !(d->options->general & CL_SCAN_GENERAL_HEURISTIC_PRECEDENCE))

@ -273,6 +273,8 @@ static void clamscan_virus_found_cb(int fd, const char *virname, void *context)
struct clamscan_cb_data *data = (struct clamscan_cb_data *)context;
const char *filename;
UNUSEDPARAM(fd);
if (data == NULL)
return;
if (data->filename != NULL)

@ -35,7 +35,7 @@
#define CL_TYPENO 500
#define MAX_EMBEDDED_OBJ 10
typedef enum {
typedef enum cli_file {
CL_TYPE_ANY = 0,
CL_TYPE_TEXT_ASCII = CL_TYPENO, /* X3.4, ISO-8859, non-ISO ext. ASCII */
CL_TYPE_TEXT_UTF8,

@ -368,6 +368,8 @@ int cli_hwp5header(cli_ctx *ctx, hwp5_header_t *hwp5)
static int hwp5_cb(void *cbdata, int fd, const char *filepath, cli_ctx *ctx)
{
UNUSEDPARAM(cbdata);
if (fd < 0 || !ctx)
return CL_ENULLARG;
@ -1507,21 +1509,15 @@ static inline int parsehwp3_paragraph(cli_ctx *ctx, fmap_t *map, int p, int leve
return CL_SUCCESS;
}
static inline int parsehwp3_infoblk_0(cli_ctx *ctx, fmap_t *dmap, off_t *offset, int *last)
{
uint16_t infoid, infolen;
fmap_t *map = (dmap ? dmap : *ctx->fmap);
return CL_SUCCESS;
}
static inline int parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, off_t *offset, int *last)
{
uint32_t infoid, infolen;
fmap_t *map = (dmap ? dmap : *ctx->fmap);
int i, count, ret = CL_SUCCESS;
long long unsigned infoloc = (long long unsigned)(*offset);
#if HWP3_DEBUG
char field[HWP3_FIELD_LENGTH];
#endif
#if HAVE_JSON
json_object *infoblk_1, *contents, *counter, *entry;
#endif
@ -1753,12 +1749,14 @@ static int hwp3_cb(void *cbdata, int fd, const char *filepath, cli_ctx *ctx)
{
fmap_t *map, *dmap;
off_t offset, start, new_offset;
int i, t = 0, p = 0, last = 0, ret = CL_SUCCESS;
int i, p = 0, last = 0, ret = CL_SUCCESS;
uint16_t nstyles;
#if HAVE_JSON
json_object *fonts;
#endif
UNUSEDPARAM(filepath);
offset = start = cbdata ? *(off_t *)cbdata : 0;
if (offset == 0) {
@ -1967,6 +1965,8 @@ static size_t num_hwpml_keys = sizeof(hwpml_keys) / sizeof(struct key_entry);
/* binary streams needs to be base64-decoded then decompressed if fields are set */
static int hwpml_scan_cb(void *cbdata, int fd, const char *filepath, cli_ctx *ctx)
{
UNUSEDPARAM(cbdata);
if (fd < 0 || !ctx)
return CL_ENULLARG;
@ -2106,7 +2106,7 @@ int cli_scanhwpml(cli_ctx *ctx)
struct msxml_cbdata cbdata;
struct msxml_ctx mxctx;
xmlTextReaderPtr reader = NULL;
int state, ret = CL_SUCCESS;
int ret = CL_SUCCESS;
cli_dbgmsg("in cli_scanhwpml()\n");

@ -45,7 +45,7 @@
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
*
*
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
@ -107,8 +107,11 @@ struct lzw_internal_state {
code_t *dec_codetab; /* kept separate for small machines */
};
#define LZW_ENABLE_PRINT_DEBUGGING 0
#if LZW_ENABLE_PRINT_DEBUGGING
static void code_print(code_t *code);
static void dict_print(code_t *codetab, uint16_t start, uint16_t maxcode);
#endif
#define GetNextCode(code) \
{ \
@ -418,6 +421,7 @@ int lzwInflateEnd(lzw_streamp strm)
return LZW_OK;
}
#if LZW_ENABLE_PRINT_DEBUGGING
static void code_print(code_t *code)
{
code_t *cpt = code;
@ -451,3 +455,4 @@ static void dict_print(code_t *codetab, uint16_t start, uint16_t maxcode)
code_print(codetab + i);
}
}
#endif

@ -308,7 +308,7 @@ static int cli_ac_addpatt_recursive(struct cli_matcher *root, struct cli_ac_patt
return cli_ac_addpatt_recursive(root, pattern, next, i + 1, len);
}
int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
cl_error_t cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
{
struct cli_ac_patt **newtable;
uint16_t len = MIN(root->ac_maxdepth, pattern->length[0]);
@ -482,7 +482,7 @@ static int ac_maketrans(struct cli_matcher *root)
return CL_SUCCESS;
}
int cli_ac_buildtrie(struct cli_matcher *root)
cl_error_t cli_ac_buildtrie(struct cli_matcher *root)
{
if (!root)
return CL_EMALFDB;
@ -498,7 +498,7 @@ int cli_ac_buildtrie(struct cli_matcher *root)
return ac_maketrans(root);
}
int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth, uint8_t dconf_prefiltering)
cl_error_t cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth, uint8_t dconf_prefiltering)
{
#ifdef USE_MPOOL
assert(root->mempool && "mempool must be initialized");
@ -1247,7 +1247,7 @@ inline static int ac_findmatch(const unsigned char *buffer, uint32_t offset, uin
return 0;
}
int cli_ac_initdata(struct cli_ac_data *data, uint32_t partsigs, uint32_t lsigs, uint32_t reloffsigs, uint8_t tracklen)
cl_error_t cli_ac_initdata(struct cli_ac_data *data, uint32_t partsigs, uint32_t lsigs, uint32_t reloffsigs, uint8_t tracklen)
{
unsigned int i, j;
@ -1396,7 +1396,7 @@ int cli_ac_initdata(struct cli_ac_data *data, uint32_t partsigs, uint32_t lsigs,
return CL_SUCCESS;
}
int cli_ac_caloff(const struct cli_matcher *root, struct cli_ac_data *data, const struct cli_target_info *info)
cl_error_t cli_ac_caloff(const struct cli_matcher *root, struct cli_ac_data *data, const struct cli_target_info *info)
{
int ret;
unsigned int i;
@ -1507,7 +1507,7 @@ inline static int ac_addtype(struct cli_matched_type **list, cli_file_t type, of
return CL_SUCCESS;
}
int lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t lsigid1, uint32_t lsigid2, uint32_t realoff, int partial)
cl_error_t lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t lsigid1, uint32_t lsigid2, uint32_t realoff, int partial)
{
const struct cli_ac_lsig *ac_lsig = root->ac_lsigtable[lsigid1];
const struct cli_lsig_tdb *tdb = &ac_lsig->tdb;
@ -1602,7 +1602,7 @@ int lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata,
return CL_SUCCESS;
}
int cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigned lsigid1)
cl_error_t cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigned lsigid1)
{
const struct cli_lsig_tdb *tdb = &root->ac_lsigtable[lsigid1]->tdb;
unsigned i;
@ -1618,7 +1618,7 @@ int cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigned
return CL_SUCCESS;
}
int cli_ac_scanbuff(
cl_error_t cli_ac_scanbuff(
const unsigned char *buffer,
uint32_t length,
const char **virname,
@ -2405,7 +2405,7 @@ inline static int ac_special_altstr(const char *hexpr, uint8_t sigopts, struct c
}
/* FIXME: clean up the code */
int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, const uint32_t *lsigid, unsigned int options)
cl_error_t cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, const uint32_t *lsigid, unsigned int options)
{
struct cli_ac_patt *new;
char *pt, *pt2, *hex = NULL, *hexcpy = NULL;

@ -128,17 +128,17 @@ struct cli_ac_result {
#include "matcher.h"
int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern);
int cli_ac_initdata(struct cli_ac_data *data, uint32_t partsigs, uint32_t lsigs, uint32_t reloffsigs, uint8_t tracklen);
int lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t lsigid1, uint32_t lsigid2, uint32_t realoff, int partial);
int cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigned lsigid1);
cl_error_t cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern);
cl_error_t cli_ac_initdata(struct cli_ac_data *data, uint32_t partsigs, uint32_t lsigs, uint32_t reloffsigs, uint8_t tracklen);
cl_error_t lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t lsigid1, uint32_t lsigid2, uint32_t realoff, int partial);
cl_error_t cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigned lsigid1);
int cli_ac_chklsig(const char *expr, const char *end, uint32_t *lsigcnt, unsigned int *cnt, uint64_t *ids, unsigned int parse_only);
void cli_ac_freedata(struct cli_ac_data *data);
int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, void **customdata, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t offset, cli_file_t ftype, struct cli_matched_type **ftoffset, unsigned int mode, cli_ctx *ctx);
int cli_ac_buildtrie(struct cli_matcher *root);
int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth, uint8_t dconf_prefiltering);
int cli_ac_caloff(const struct cli_matcher *root, struct cli_ac_data *data, const struct cli_target_info *info);
cl_error_t cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, void **customdata, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t offset, cli_file_t ftype, struct cli_matched_type **ftoffset, unsigned int mode, cli_ctx *ctx);
cl_error_t cli_ac_buildtrie(struct cli_matcher *root);
cl_error_t cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth, uint8_t dconf_prefiltering);
cl_error_t cli_ac_caloff(const struct cli_matcher *root, struct cli_ac_data *data, const struct cli_target_info *info);
void cli_ac_free(struct cli_matcher *root);
int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, const uint32_t *lsigid, unsigned int options);
cl_error_t cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, const uint32_t *lsigid, unsigned int options);
#endif

@ -40,19 +40,19 @@
#define BM_BLOCK_SIZE 3
#define HASH(a, b, c) (211 * a + 37 * b + c)
int cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const char *offset)
cl_error_t cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const char *offset)
{
uint16_t idx, i;
const unsigned char *pt = pattern->pattern;
struct cli_bm_patt *prev, *next = NULL;
int ret;
cl_error_t ret;
if (pattern->length < BM_MIN_LENGTH) {
cli_errmsg("cli_bm_addpatt: Signature for %s is too short\n", pattern->virname);
return CL_EMALFDB;
}
if ((ret = cli_caloff(offset, NULL, root->type, pattern->offdata, &pattern->offset_min, &pattern->offset_max))) {
if (CL_SUCCESS != (ret = cli_caloff(offset, NULL, root->type, pattern->offdata, &pattern->offset_min, &pattern->offset_max))) {
cli_errmsg("cli_bm_addpatt: Can't calculate offset for signature %s\n", pattern->virname);
return ret;
}
@ -133,7 +133,7 @@ int cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const
return CL_SUCCESS;
}
int cli_bm_init(struct cli_matcher *root)
cl_error_t cli_bm_init(struct cli_matcher *root)
{
uint16_t i, size = HASH(255, 255, 255) + 1;
#ifdef USE_MPOOL
@ -154,9 +154,9 @@ int cli_bm_init(struct cli_matcher *root)
return CL_SUCCESS;
}
int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, const struct cli_target_info *info)
cl_error_t cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, const struct cli_target_info *info)
{
int ret;
cl_error_t ret;
unsigned int i;
struct cli_bm_patt *patt;
@ -185,7 +185,7 @@ int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, cons
if (data->offtab[data->cnt] >= info->fsize)
continue;
data->cnt++;
} else if ((ret = cli_caloff(NULL, info, root->type, patt->offdata, &data->offset[patt->offset_min], NULL))) {
} else if (CL_SUCCESS != (ret = cli_caloff(NULL, info, root->type, patt->offdata, &data->offset[patt->offset_min], NULL))) {
cli_errmsg("cli_bm_initoff: Can't calculate relative offset in signature for %s\n", patt->virname);
free(data->offtab);
free(data->offset);
@ -242,7 +242,7 @@ void cli_bm_free(struct cli_matcher *root)
}
}
int cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cli_bm_patt **patt, const struct cli_matcher *root, uint32_t offset, const struct cli_target_info *info, struct cli_bm_off *offdata, cli_ctx *ctx)
cl_error_t cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cli_bm_patt **patt, const struct cli_matcher *root, uint32_t offset, const struct cli_target_info *info, struct cli_bm_off *offdata, cli_ctx *ctx)
{
uint32_t i, j, off, off_min, off_max;
uint8_t found, pchain, shift;
@ -250,7 +250,8 @@ int cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
struct cli_bm_patt *p;
const unsigned char *bp, *pt;
unsigned char prefix;
int ret, viruses_found = 0;
cl_error_t ret;
int viruses_found = 0;
if (!root || !root->bm_shift)
return CL_CLEAN;

@ -45,11 +45,11 @@ struct cli_bm_off {
uint32_t *offset, *offtab, cnt, pos;
};
int cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const char *offset);
int cli_bm_init(struct cli_matcher *root);
int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, const struct cli_target_info *info);
cl_error_t cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const char *offset);
cl_error_t cli_bm_init(struct cli_matcher *root);
cl_error_t cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, const struct cli_target_info *info);
void cli_bm_freeoff(struct cli_bm_off *data);
int cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cli_bm_patt **patt, const struct cli_matcher *root, uint32_t offset, const struct cli_target_info *info, struct cli_bm_off *offdata, cli_ctx *ctx);
cl_error_t cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cli_bm_patt **patt, const struct cli_matcher *root, uint32_t offset, const struct cli_target_info *info, struct cli_bm_off *offdata, cli_ctx *ctx);
void cli_bm_free(struct cli_matcher *root);
#endif

@ -74,7 +74,6 @@ cl_error_t cli_bcomp_addpatt(struct cli_matcher *root, const char *virname, cons
char *comp_buf = NULL;
char *comp_start = NULL;
char *comp_end = NULL;
char *hexcpy = NULL;
if (!hexsig || !(*hexsig) || !root || !virname) {
return CL_ENULLARG;
@ -455,7 +454,7 @@ cl_error_t cli_bcomp_addpatt(struct cli_matcher *root, const char *virname, cons
cl_error_t cli_bcomp_scanbuf(const unsigned char *buffer, size_t buffer_length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, cli_ctx *ctx)
{
int64_t i = 0, rc = 0, ret = CL_SUCCESS;
int64_t i = 0, ret = CL_SUCCESS;
uint32_t lsigid, ref_subsigid;
uint32_t offset = 0;
uint8_t viruses_found = 0;

@ -197,7 +197,7 @@ int cli_pcre_init()
return cli_pcre_init_internal();
}
int cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const char *trigger, const char *pattern, const char *cflags, const char *offset, const uint32_t *lsigid, unsigned int options)
cl_error_t cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const char *trigger, const char *pattern, const char *cflags, const char *offset, const uint32_t *lsigid, unsigned int options)
{
struct cli_pcre_meta **newmetatable = NULL, *pm = NULL;
uint32_t pcre_count;
@ -394,10 +394,10 @@ int cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const char *
return CL_SUCCESS;
}
int cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, long long unsigned recmatch_limit, const struct cli_dconf *dconf)
cl_error_t cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, long long unsigned recmatch_limit, const struct cli_dconf *dconf)
{
unsigned int i;
int ret;
cl_error_t ret;
struct cli_pcre_meta *pm = NULL;
int disable_all = 0;
@ -459,10 +459,10 @@ int cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, lon
}
/* TODO - handle VI and Macro offset types */
int cli_pcre_recaloff(struct cli_matcher *root, struct cli_pcre_off *data, struct cli_target_info *info, cli_ctx *ctx)
cl_error_t cli_pcre_recaloff(struct cli_matcher *root, struct cli_pcre_off *data, struct cli_target_info *info, cli_ctx *ctx)
{
/* TANGENT: maintain relative offset data in cli_ac_data? */
int ret;
cl_error_t ret;
unsigned int i;
struct cli_pcre_meta *pm;
uint32_t endoff;
@ -575,15 +575,15 @@ int cli_pcre_qoff(struct cli_pcre_meta *pm, uint32_t length, uint32_t *adjbuffer
return CL_SUCCESS;
}
int cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, const struct cli_pcre_off *data, cli_ctx *ctx)
cl_error_t cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, const struct cli_pcre_off *data, cli_ctx *ctx)
{
struct cli_pcre_meta **metatable = root->pcre_metatable, *pm = NULL;
struct cli_pcre_meta *pm = NULL;
struct cli_pcre_data *pd;
struct cli_pcre_results p_res;
struct cli_ac_result *newres;
uint32_t adjbuffer, adjshift, adjlength;
unsigned int i, evalcnt = 0;
uint64_t maxfilesize, evalids = 0;
unsigned int i, evalcnt = 0;
uint64_t evalids = 0;
uint32_t global, encompass, rolling;
int rc = 0, offset = 0, ret = CL_SUCCESS, options = 0;
uint8_t viruses_found = 0;

@ -73,11 +73,11 @@ void cli_pcre_perf_events_destroy();
/* PCRE MATCHER DECLARATIONS */
int cli_pcre_init();
int cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const char *trigger, const char *pattern, const char *cflags, const char *offset, const uint32_t *lsigid, unsigned int options);
int cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, long long unsigned recmatch_limit, const struct cli_dconf *dconf);
int cli_pcre_recaloff(struct cli_matcher *root, struct cli_pcre_off *data, struct cli_target_info *info, cli_ctx *ctx);
cl_error_t cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const char *trigger, const char *pattern, const char *cflags, const char *offset, const uint32_t *lsigid, unsigned int options);
cl_error_t cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, long long unsigned recmatch_limit, const struct cli_dconf *dconf);
cl_error_t cli_pcre_recaloff(struct cli_matcher *root, struct cli_pcre_off *data, struct cli_target_info *info, cli_ctx *ctx);
void cli_pcre_freeoff(struct cli_pcre_off *data);
int cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, const struct cli_pcre_off *data, cli_ctx *ctx);
cl_error_t cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, const struct cli_pcre_off *data, cli_ctx *ctx);
void cli_pcre_freemeta(struct cli_matcher *root, struct cli_pcre_meta *pm);
void cli_pcre_freetable(struct cli_matcher *root);
#else

@ -258,9 +258,9 @@ static inline int matcher_run(const struct cli_matcher *root,
return ret;
}
int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata)
cl_error_t cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata)
{
int ret = CL_CLEAN;
cl_error_t ret = CL_CLEAN;
unsigned int i = 0, j = 0, viruses_found = 0;
struct cli_ac_data mdata;
struct cli_matcher *groot, *troot = NULL;
@ -327,7 +327,7 @@ int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset,
* offdata[2]: max shift
* offdata[3]: section number
*/
int cli_caloff(const char *offstr, const struct cli_target_info *info, unsigned int target, uint32_t *offdata, uint32_t *offset_min, uint32_t *offset_max)
cl_error_t cli_caloff(const char *offstr, const struct cli_target_info *info, unsigned int target, uint32_t *offdata, uint32_t *offset_min, uint32_t *offset_max)
{
char offcpy[65];
unsigned int n, val;
@ -575,12 +575,12 @@ void cli_targetinfo_destroy(struct cli_target_info *info)
info->status = 0;
}
int cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx)
cl_error_t cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx)
{
return cli_checkfp_virus(digest, size, ctx, NULL);
}
int cli_checkfp_virus(unsigned char *digest, size_t size, cli_ctx *ctx, const char *vname)
cl_error_t cli_checkfp_virus(unsigned char *digest, size_t size, cli_ctx *ctx, const char *vname)
{
char md5[33];
unsigned int i;
@ -759,9 +759,10 @@ int32_t cli_bcapi_matchicon(struct cli_bc_ctx *ctx, const uint8_t *grp1, int32_t
return ret;
}
int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres)
cl_error_t cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres)
{
int ret = CL_EMEM, empty;
cl_error_t ret = CL_EMEM;
int empty;
fmap_t *map = *ctx->fmap;
if ((*ctx->fmap = fmap_check_empty(desc, 0, 0, &empty))) {
@ -892,11 +893,11 @@ static int yara_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data
}
#endif
int cli_exp_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *acdata, struct cli_target_info *target_info, const char *hash)
cl_error_t cli_exp_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *acdata, struct cli_target_info *target_info, const char *hash)
{
uint8_t viruses_found = 0;
uint32_t i;
int32_t rc = CL_SUCCESS;
cl_error_t rc = CL_SUCCESS;
for (i = 0; i < root->ac_lsigs; i++) {
if (root->ac_lsigtable[i]->type == CLI_LSIG_NORMAL)
@ -917,10 +918,11 @@ int cli_exp_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *acd
return CL_CLEAN;
}
int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres, unsigned char *refhash)
cl_error_t cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres, unsigned char *refhash)
{
const unsigned char *buff;
int ret = CL_CLEAN, type = CL_CLEAN, compute_hash[CLI_HASH_AVAIL_TYPES];
cl_error_t ret = CL_CLEAN, type = CL_CLEAN;
int compute_hash[CLI_HASH_AVAIL_TYPES];
unsigned int i = 0, j = 0, bm_offmode = 0;
uint32_t maxpatlen, bytes, offset = 0;
struct cli_ac_data gdata, tdata;
@ -1005,7 +1007,7 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
* called first for PEs, and we want to determine the whitelist/blacklist
* status early on so we can skip things like embedded PE extraction
* (which is broken for signed binaries within signed binaries).
*
*
* If we want to add support for more signature parsing in the future
* (Ex: MachO sigs), do that here too.
*
@ -1316,11 +1318,11 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
return (acmode & AC_SCAN_FT) ? type : CL_CLEAN;
}
int cli_matchmeta(cli_ctx *ctx, const char *fname, size_t fsizec, size_t fsizer, int encrypted, unsigned int filepos, int res1, void *res2)
cl_error_t cli_matchmeta(cli_ctx *ctx, const char *fname, size_t fsizec, size_t fsizer, int encrypted, unsigned int filepos, int res1, void *res2)
{
const struct cli_cdb *cdb;
unsigned int viruses_found = 0;
int ret = CL_CLEAN;
cl_error_t ret = CL_CLEAN;
cli_dbgmsg("CDBNAME:%s:%llu:%s:%llu:%llu:%d:%u:%u:%p\n",
cli_ftname(cli_get_container(ctx, -1)), (long long unsigned)fsizec, fname, (long long unsigned)fsizec, (long long unsigned)fsizer,

@ -215,17 +215,17 @@ static const struct cli_mtarget cli_mtargets[CLI_MTARGETS] = {
// clang-format on
int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata);
cl_error_t cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata);
int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres);
int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres, unsigned char *refhash);
int cli_exp_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *acdata, struct cli_target_info *target_info, const char *hash);
int cli_caloff(const char *offstr, const struct cli_target_info *info, unsigned int target, uint32_t *offdata, uint32_t *offset_min, uint32_t *offset_max);
cl_error_t cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres);
cl_error_t cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres, unsigned char *refhash);
cl_error_t cli_exp_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *acdata, struct cli_target_info *target_info, const char *hash);
cl_error_t cli_caloff(const char *offstr, const struct cli_target_info *info, unsigned int target, uint32_t *offdata, uint32_t *offset_min, uint32_t *offset_max);
int cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx);
int cli_checkfp_virus(unsigned char *digest, size_t size, cli_ctx *ctx, const char *vname);
cl_error_t cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx);
cl_error_t cli_checkfp_virus(unsigned char *digest, size_t size, cli_ctx *ctx, const char *vname);
int cli_matchmeta(cli_ctx *ctx, const char *fname, size_t fsizec, size_t fsizer, int encrypted, unsigned int filepos, int res1, void *res2);
cl_error_t cli_matchmeta(cli_ctx *ctx, const char *fname, size_t fsizec, size_t fsizer, int encrypted, unsigned int filepos, int res1, void *res2);
void cli_targetinfo(struct cli_target_info *info, unsigned int target, fmap_t *map);

@ -1118,9 +1118,6 @@ parseMHTMLComment(const char *comment, cli_ctx *ctx, void *wrkjobj, void *cbdata
#if HAVE_LIBXML2
const char *xmlsrt, *xmlend;
xmlTextReaderPtr reader;
#if HAVE_JSON
json_object *thisjobj = (json_object *)wrkjobj;
#endif
int ret = CL_SUCCESS;
UNUSEDPARAM(cbdata);
@ -3831,7 +3828,6 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m
message *aMessage = messages[i];
const int doPhishingScan = mctx->ctx->engine->dboptions & CL_DB_PHISHING_URLS && (DCONF_PHISHING & PHISHING_CONF_ENGINE);
#if HAVE_JSON
const char *mtype = NULL;
json_object *thisobj = NULL, *saveobj = mctx->wrkobj;
if (mctx->wrkobj != NULL) {

@ -59,6 +59,8 @@ ole2_convert_utf(summary_ctx_t *sctx, char *begin, size_t sz, const char *encodi
size_t inlen, outlen, nonrev, sz2;
int i, attempt;
iconv_t cd;
#else
UNUSEDPARAM(encoding);
#endif
/* applies in the both case */
if (sctx->codepage == 20127 || sctx->codepage == 65001) {

@ -224,12 +224,12 @@ int msxml_read_cb(void *ctx, char *buffer, int len)
}
#endif
int cli_scanmsxml(cli_ctx *ctx)
cl_error_t cli_scanmsxml(cli_ctx *ctx)
{
#if HAVE_LIBXML2
struct msxml_cbdata cbdata;
xmlTextReaderPtr reader = NULL;
int state, ret = CL_SUCCESS;
cl_error_t ret = CL_SUCCESS;
cli_dbgmsg("in cli_scanmsxml()\n");

@ -49,6 +49,6 @@ struct msxml_cbdata {
};
int msxml_read_cb(void *ctx, char *buffer, int len);
int cli_scanmsxml(cli_ctx *ctx);
cl_error_t cli_scanmsxml(cli_ctx *ctx);
#endif /* __MSXML_H */

@ -1117,7 +1117,7 @@ int cli_append_possibly_unwanted(cli_ctx *ctx, const char *virname)
return CL_CLEAN;
}
int cli_append_virus(cli_ctx *ctx, const char *virname)
cl_error_t cli_append_virus(cli_ctx *ctx, const char *virname)
{
if (ctx->virname == NULL)
return CL_CLEAN;

@ -635,7 +635,7 @@ static inline void cli_writeint32(void *offset, uint32_t value)
}
#endif
int cli_append_virus(cli_ctx *ctx, const char *virname);
cl_error_t cli_append_virus(cli_ctx *ctx, const char *virname);
const char *cli_get_last_virus(const cli_ctx *ctx);
const char *cli_get_last_virus_str(const cli_ctx *ctx);
void cli_virus_found_cb(cli_ctx *ctx);

@ -994,7 +994,6 @@ char *cli_gentemp_with_prefix(const char *dir, const char *prefix)
char *fname;
char *fullpath;
const char *mdir;
int i;
size_t len;
mdir = dir ? dir : cli_gettmpdir();

@ -668,7 +668,7 @@ static cl_error_t filter_flatedecode(struct pdf_struct *pdf, struct pdf_obj *obj
uint8_t *content = (uint8_t *)token->content;
uint32_t length = token->length;
z_stream stream;
int zstat, skip = 0, rc = CL_SUCCESS;
int zstat, rc = CL_SUCCESS;
UNUSEDPARAM(params);
@ -912,7 +912,7 @@ static cl_error_t filter_lzwdecode(struct pdf_struct *pdf, struct pdf_obj *obj,
uint8_t *content = (uint8_t *)token->content;
uint32_t length = token->length;
lzw_stream stream;
int echg = 1, lzwstat, skip = 0, rc = CL_SUCCESS;
int echg = 1, lzwstat, rc = CL_SUCCESS;
if (pdf->ctx && !(pdf->ctx->dconf->other & OTHER_CONF_LZW))
return CL_BREAK;

@ -42,14 +42,14 @@
#include "mpool.h"
int whitelist_match(const struct cl_engine* engine, char* real_url, const char* display_url, int hostOnly)
cl_error_t whitelist_match(const struct cl_engine* engine, char* real_url, const char* display_url, int hostOnly)
{
const char* info; /*unused*/
cli_dbgmsg("Phishing: looking up in whitelist: %s:%s; host-only:%d\n", real_url, display_url, hostOnly);
return engine->whitelist_matcher ? regex_list_match(engine->whitelist_matcher, real_url, display_url, NULL, hostOnly, &info, 1) : 0;
}
int init_whitelist(struct cl_engine* engine)
cl_error_t init_whitelist(struct cl_engine* engine)
{
if (engine) {
engine->whitelist_matcher = (struct regex_matcher*)mpool_malloc(engine->mempool, sizeof(struct regex_matcher));

@ -26,10 +26,10 @@
#include "clamav.h"
int init_whitelist(struct cl_engine* engine);
cl_error_t init_whitelist(struct cl_engine* engine);
void whitelist_done(struct cl_engine* engine);
void whitelist_cleanup(const struct cl_engine* engine);
int is_whitelist_ok(const struct cl_engine* engine);
int whitelist_match(const struct cl_engine* engine, char* real_url, const char* display_url, int hostOnly);
cl_error_t whitelist_match(const struct cl_engine* engine, char* real_url, const char* display_url, int hostOnly);
#endif

@ -848,7 +848,7 @@ static void free_regex(regex_t* p)
}
}
int phishing_init(struct cl_engine* engine)
cl_error_t phishing_init(struct cl_engine* engine)
{
struct phishcheck* pchk;
if (!engine->phishcheck) {
@ -1160,12 +1160,12 @@ static enum phish_status phishy_map(int phishy, enum phish_status fallback)
return fallback;
}
static int whitelist_check(const struct cl_engine* engine, struct url_check* urls, int hostOnly)
static cl_error_t whitelist_check(const struct cl_engine* engine, struct url_check* urls, int hostOnly)
{
return whitelist_match(engine, urls->realLink.data, urls->displayLink.data, hostOnly);
}
static int hash_match(const struct regex_matcher* rlist, const char* host, size_t hlen, const char* path, size_t plen, int* prefix_matched)
static cl_error_t hash_match(const struct regex_matcher* rlist, const char* host, size_t hlen, const char* path, size_t plen, int* prefix_matched)
{
const char* virname;
#if 0
@ -1227,7 +1227,7 @@ static int hash_match(const struct regex_matcher* rlist, const char* host, size_
#define URL_MAX_LEN 1024
#define COMPONENTS 4
int cli_url_canon(const char* inurl, size_t len, char* urlbuff, size_t dest_len, char** host, size_t* hostlen, const char** path, size_t* pathlen)
enum phish_status cli_url_canon(const char* inurl, size_t len, char* urlbuff, size_t dest_len, char** host, size_t* hostlen, const char** path, size_t* pathlen)
{
char *url, *p, *last;
char *host_begin, *path_begin;
@ -1331,7 +1331,7 @@ int cli_url_canon(const char* inurl, size_t len, char* urlbuff, size_t dest_len,
return CL_PHISH_NODECISION;
}
static int url_hash_match(const struct regex_matcher* rlist, const char* inurl, size_t len)
static cl_error_t url_hash_match(const struct regex_matcher* rlist, const char* inurl, size_t len)
{
size_t j, k, ji, ki;
char* host_begin;
@ -1340,7 +1340,9 @@ static int url_hash_match(const struct regex_matcher* rlist, const char* inurl,
size_t path_len;
size_t host_len;
char* p;
int rc, prefix_matched = 0;
enum phish_status phish_rc;
cl_error_t rc;
int prefix_matched = 0;
const char* lp[COMPONENTS + 1];
size_t pp[COMPONENTS + 2];
char urlbuff[URL_MAX_LEN + 3]; /* htmlnorm truncates at 1024 bytes + terminating null + slash + host end null */
@ -1354,9 +1356,9 @@ static int url_hash_match(const struct regex_matcher* rlist, const char* inurl,
if (!inurl)
return CL_EMEM;
rc = cli_url_canon(inurl, len, urlbuff, sizeof(urlbuff), &host_begin, &host_len, &path_begin, &path_len);
if (rc == CL_PHISH_CLEAN)
return rc;
phish_rc = cli_url_canon(inurl, len, urlbuff, sizeof(urlbuff), &host_begin, &host_len, &path_begin, &path_len);
if (phish_rc == CL_PHISH_CLEAN)
return CL_CLEAN;
/* get last 5 components of hostname */
j = COMPONENTS;
@ -1403,7 +1405,7 @@ static int url_hash_match(const struct regex_matcher* rlist, const char* inurl,
/* lookup prefix/suffix hashes of URL */
rc = hash_match(rlist, lp[ji], host_begin + host_len - lp[ji] + 1, path_begin, pp[ki],
need_prefixmatch ? &prefix_matched : NULL);
if (rc) {
if (CL_CLEAN != rc) {
return rc;
}
count++;

@ -78,9 +78,9 @@ int phishingScan(cli_ctx* ctx, tag_arguments_t* hrefs);
void phish_disable(struct cl_engine* engine, const char* reason);
/* Global, non-thread-safe functions, call only once! */
int phishing_init(struct cl_engine* engine);
cl_error_t phishing_init(struct cl_engine* engine);
void phishing_done(struct cl_engine* engine);
int cli_url_canon(const char* inurl, size_t len, char* urlbuff, size_t dest_len, char** host, size_t* hostlen, const char** path, size_t* pathlen);
enum phish_status cli_url_canon(const char* inurl, size_t len, char* urlbuff, size_t dest_len, char** host, size_t* hostlen, const char** path, size_t* pathlen);
/* end of non-thread-safe functions */
#endif

@ -117,7 +117,7 @@ char *cli_virname(const char *virname, unsigned int official)
return newname;
}
int cli_sigopts_handler(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options)
cl_error_t cli_sigopts_handler(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options)
{
char *hexcpy, *start, *end, *mid;
unsigned int i;
@ -303,7 +303,7 @@ int cli_sigopts_handler(struct cli_matcher *root, const char *virname, const cha
}
#define PCRE_TOKENS 4
int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options)
cl_error_t cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options)
{
struct cli_bm_patt *bm_new;
char *pt, *hexcpy, *start = NULL, *mid = NULL, *end = NULL, *n, l, r;
@ -591,13 +591,13 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
} else if ((start = strchr(hexsig, '(')) && (mid = strchr(hexsig, '#')) && (end = strrchr(hexsig, '#')) && mid != end) {
/* format seems to match byte_compare */
if (ret = cli_bcomp_addpatt(root, virname, hexsig, lsigid, options)) {
if (CL_SUCCESS != (ret = cli_bcomp_addpatt(root, virname, hexsig, lsigid, options))) {
cli_errmsg("cli_parse_add(): Problem adding signature (2b).\n");
return ret;
}
} else if (root->ac_only || type || lsigid || sigopts || strpbrk(hexsig, "?([") || (root->bm_offmode && (!strcmp(offset, "*") || strchr(offset, ','))) || strstr(offset, "VI") || strchr(offset, '$')) {
if ((ret = cli_ac_addsig(root, virname, hexsig, sigopts, 0, 0, 0, rtype, type, 0, 0, offset, lsigid, options))) {
if (CL_SUCCESS != (ret = cli_ac_addsig(root, virname, hexsig, sigopts, 0, 0, 0, rtype, type, 0, 0, offset, lsigid, options))) {
cli_errmsg("cli_parse_add(): Problem adding signature (3).\n");
return ret;
}
@ -624,7 +624,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
if (bm_new->length > root->maxpatlen)
root->maxpatlen = bm_new->length;
if ((ret = cli_bm_addpatt(root, bm_new, offset))) {
if (CL_SUCCESS != (ret = cli_bm_addpatt(root, bm_new, offset))) {
cli_errmsg("cli_parse_add(): Problem adding signature (4).\n");
mpool_free(root->mempool, bm_new->pattern);
mpool_free(root->mempool, bm_new->virname);
@ -636,7 +636,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
return CL_SUCCESS;
}
int cli_initroots(struct cl_engine *engine, unsigned int options)
cl_error_t cli_initroots(struct cl_engine *engine, unsigned int options)
{
int i, ret;
struct cli_matcher *root;
@ -659,7 +659,7 @@ int cli_initroots(struct cl_engine *engine, unsigned int options)
root->ac_only = 1;
cli_dbgmsg("Initializing AC pattern matcher of root[%d]\n", i);
if ((ret = cli_ac_init(root, engine->ac_mindepth, engine->ac_maxdepth, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
if (CL_SUCCESS != (ret = cli_ac_init(root, engine->ac_mindepth, engine->ac_maxdepth, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
/* no need to free previously allocated memory here */
cli_errmsg("cli_initroots: Can't initialise AC pattern matcher\n");
return ret;
@ -667,7 +667,7 @@ int cli_initroots(struct cl_engine *engine, unsigned int options)
if (!root->ac_only) {
cli_dbgmsg("cli_initroots: Initializing BM tables of root[%d]\n", i);
if ((ret = cli_bm_init(root))) {
if (CL_SUCCESS != (ret = cli_bm_init(root))) {
cli_errmsg("cli_initroots: Can't initialise BM pattern matcher\n");
return ret;
}
@ -886,7 +886,7 @@ static int cli_chkpua(const char *signame, const char *pua_cats, unsigned int op
return ret;
}
static int cli_loaddb(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio, const char *dbname)
static cl_error_t cli_loaddb(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio, const char *dbname)
{
char buffer[FILEBUFF], *buffer_cpy = NULL, *pt, *start;
unsigned int line = 0, sigs = 0;
@ -895,7 +895,7 @@ static int cli_loaddb(FILE *fs, struct cl_engine *engine, unsigned int *signo, u
UNUSEDPARAM(dbname);
if ((ret = cli_initroots(engine, options)))
if (CL_SUCCESS != (ret = cli_initroots(engine, options)))
return ret;
root = engine->root[0];
@ -934,7 +934,7 @@ static int cli_loaddb(FILE *fs, struct cl_engine *engine, unsigned int *signo, u
if (*pt == '=') continue;
if ((ret = cli_parse_add(root, start, pt, 0, 0, 0, "*", 0, NULL, options))) {
if (CL_SUCCESS != (ret = cli_parse_add(root, start, pt, 0, 0, 0, "*", 0, NULL, options))) {
cli_dbgmsg("cli_loaddb: cli_parse_add failed on line %d\n", line);
ret = CL_EMALFDB;
break;
@ -962,7 +962,7 @@ static int cli_loaddb(FILE *fs, struct cl_engine *engine, unsigned int *signo, u
}
#define ICO_TOKENS 4
static int cli_loadidb(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio)
static cl_error_t cli_loadidb(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio)
{
const char *tokens[ICO_TOKENS + 1];
char buffer[FILEBUFF], *buffer_cpy = NULL;
@ -1202,12 +1202,12 @@ static int cli_loadwdb(FILE *fs, struct cl_engine *engine, unsigned int options,
return CL_SUCCESS;
if (!engine->whitelist_matcher) {
if ((ret = init_whitelist(engine))) {
if (CL_SUCCESS != (ret = init_whitelist(engine))) {
return ret;
}
}
if ((ret = load_regex_matcher(engine, engine->whitelist_matcher, fs, NULL, options, 1, dbio, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
if (CL_SUCCESS != (ret = load_regex_matcher(engine, engine->whitelist_matcher, fs, NULL, options, 1, dbio, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
return ret;
}
@ -1222,12 +1222,12 @@ static int cli_loadpdb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
return CL_SUCCESS;
if (!engine->domainlist_matcher) {
if ((ret = init_domainlist(engine))) {
if (CL_SUCCESS != (ret = init_domainlist(engine))) {
return ret;
}
}
if ((ret = load_regex_matcher(engine, engine->domainlist_matcher, fs, signo, options, 0, dbio, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
if (CL_SUCCESS != (ret = load_regex_matcher(engine, engine->domainlist_matcher, fs, signo, options, 0, dbio, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
return ret;
}
@ -1247,7 +1247,7 @@ static int cli_loadndb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
UNUSEDPARAM(dbname);
if ((ret = cli_initroots(engine, options)))
if (CL_SUCCESS != (ret = cli_initroots(engine, options)))
return ret;
if (engine->ignored)
@ -1331,7 +1331,7 @@ static int cli_loadndb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
offset = tokens[2];
sig = tokens[3];
if ((ret = cli_parse_add(root, virname, sig, 0, 0, 0, offset, target, NULL, options))) {
if (CL_SUCCESS != (ret = cli_parse_add(root, virname, sig, 0, 0, 0, offset, target, NULL, options))) {
ret = CL_EMALFDB;
break;
}
@ -1638,7 +1638,7 @@ static inline int init_tdb(struct cli_lsig_tdb *tdb, struct cl_engine *engine, c
#ifdef USE_MPOOL
tdb->mempool = engine->mempool;
#endif
if ((ret = lsigattribs(target, tdb))) {
if (CL_SUCCESS != (ret = lsigattribs(target, tdb))) {
FREE_TDB_P(tdb);
if (ret == 1) {
cli_dbgmsg("init_tdb: Not supported attribute(s) in signature for %s, skipping\n", virname);
@ -1769,7 +1769,7 @@ static int load_oneldb(char *buffer, int chkpua, struct cl_engine *engine, unsig
/* TDB */
memset(&tdb, 0, sizeof(tdb));
if ((ret = init_tdb(&tdb, engine, tokens[1], virname)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = init_tdb(&tdb, engine, tokens[1], virname)) != CL_SUCCESS) {
(*sigs)--;
if (ret == CL_BREAK)
return CL_SUCCESS;
@ -1890,7 +1890,7 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
unsigned int line = 0, sigs = 0;
int ret;
if ((ret = cli_initroots(engine, options)))
if (CL_SUCCESS != (ret = cli_initroots(engine, options)))
return ret;
if (engine->ignored) {
@ -2084,7 +2084,7 @@ static int cli_loadftm(FILE *fs, struct cl_engine *engine, unsigned int options,
int ret;
int magictype;
if ((ret = cli_initroots(engine, options)))
if (CL_SUCCESS != (ret = cli_initroots(engine, options)))
return ret;
while (1) {
@ -2145,7 +2145,7 @@ static int cli_loadftm(FILE *fs, struct cl_engine *engine, unsigned int options,
magictype = atoi(tokens[0]);
if (magictype == 1) { /* A-C */
if ((ret = cli_parse_add(engine->root[0], tokens[3], tokens[2], 0, rtype, type, tokens[1], 0, NULL, options)))
if (CL_SUCCESS != (ret = cli_parse_add(engine->root[0], tokens[3], tokens[2], 0, rtype, type, tokens[1], 0, NULL, options)))
break;
} else if ((magictype == 0) || (magictype == 4)) { /* memcmp() */
@ -2344,7 +2344,7 @@ static int cli_loadign(FILE *fs, struct cl_engine *engine, unsigned int options,
#ifdef USE_MPOOL
engine->ignored->mempool = engine->mempool;
#endif
if ((ret = cli_bm_init(engine->ignored))) {
if (CL_SUCCESS != (ret = cli_bm_init(engine->ignored))) {
cli_errmsg("cli_loadign: Can't initialise AC pattern matcher\n");
return ret;
}
@ -2411,7 +2411,7 @@ static int cli_loadign(FILE *fs, struct cl_engine *engine, unsigned int options,
new->length = len;
new->boundary |= BM_BOUNDARY_EOL;
if ((ret = cli_bm_addpatt(engine->ignored, new, "0"))) {
if (CL_SUCCESS != (ret = cli_bm_addpatt(engine->ignored, new, "0"))) {
if (hash)
mpool_free(engine->mempool, new->virname);
mpool_free(engine->mempool, new->pattern);
@ -2557,7 +2557,7 @@ static int cli_loadhash(FILE *fs, struct cl_engine *engine, unsigned int *signo,
break;
}
if ((ret = hm_addhash_str(db, tokens[md5_field], size, virname))) {
if (CL_SUCCESS != (ret = hm_addhash_str(db, tokens[md5_field], size, virname))) {
cli_errmsg("cli_loadhash: Malformed hash string at line %u\n", line);
mpool_free(engine->mempool, (void *)virname);
break;
@ -3292,7 +3292,7 @@ static int32_t ytable_lookup(const char *hexsig)
return -1;
}
static int ytable_add_attrib(struct cli_ytable *ytable, const char *hexsig, const char *value, int type)
static cl_error_t ytable_add_attrib(struct cli_ytable *ytable, const char *hexsig, const char *value, int type)
{
int32_t lookup;
@ -3380,7 +3380,7 @@ static int ytable_add_string(struct cli_ytable *ytable, const char *hexsig)
newtable[ytable->tbl_cnt - 1] = new;
ytable->table = newtable;
if ((ret = ytable_add_attrib(ytable, NULL, "*", 0)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = ytable_add_attrib(ytable, NULL, "*", 0)) != CL_SUCCESS) {
cli_yaramsg("ytable_add_string: failed to add default offset\n");
free(new->hexstr);
free(new);
@ -3425,7 +3425,7 @@ static int yara_hexstr_verify(YR_STRING *string, const char *hexstr, uint32_t *l
}
/* Long Check: Attempt to load hexstr */
if ((ret = cli_sigopts_handler(engine->test_root, "test-hex", hexstr, 0, 0, 0, "*", 0, lsigid, options)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = cli_sigopts_handler(engine->test_root, "test-hex", hexstr, 0, 0, 0, "*", 0, lsigid, options)) != CL_SUCCESS) {
if (ret == CL_EMALFDB) {
cli_warnmsg("load_oneyara[verify]: recovered from database loading error\n");
/* TODO: if necessary, reset testing matcher if error occurs */
@ -3581,7 +3581,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
#ifdef USE_MPOOL
engine->test_root->mempool = engine->mempool;
#endif
if ((ret = cli_ac_init(engine->test_root, engine->ac_mindepth, engine->ac_maxdepth, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
if (CL_SUCCESS != (ret = cli_ac_init(engine->test_root, engine->ac_mindepth, engine->ac_maxdepth, engine->dconf->other & OTHER_CONF_PREFILTERING))) {
cli_errmsg("load_oneyara: cannot initialize test ac root\n");
free(substr);
return ret;
@ -3690,7 +3690,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
/* modifier handler */
if (STRING_IS_NO_CASE(string)) {
cli_yaramsg("STRING_IS_NO_CASE %s\n", STRING_IS_SINGLE_MATCH(string) ? "yes" : "no");
if ((ret = ytable_add_attrib(&ytable, NULL, "i", 1)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = ytable_add_attrib(&ytable, NULL, "i", 1)) != CL_SUCCESS) {
cli_warnmsg("load_oneyara: failed to add 'nocase' sigopt\n");
str_error++;
break;
@ -3698,7 +3698,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
}
if (STRING_IS_ASCII(string)) {
cli_yaramsg("STRING_IS_ASCII %s\n", STRING_IS_SINGLE_MATCH(string) ? "yes" : "no");
if ((ret = ytable_add_attrib(&ytable, NULL, "a", 1)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = ytable_add_attrib(&ytable, NULL, "a", 1)) != CL_SUCCESS) {
cli_warnmsg("load_oneyara: failed to add 'ascii' sigopt\n");
str_error++;
break;
@ -3712,7 +3712,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
str_error++;
break;
}
if ((ret = ytable_add_attrib(&ytable, NULL, "w", 1)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = ytable_add_attrib(&ytable, NULL, "w", 1)) != CL_SUCCESS) {
cli_warnmsg("load_oneyara: failed to add 'wide' sigopt\n");
str_error++;
break;
@ -3720,7 +3720,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
}
if (STRING_IS_FULL_WORD(string)) {
cli_yaramsg("STRING_IS_FULL_WORD %s\n", STRING_IS_SINGLE_MATCH(string) ? "yes" : "no");
if ((ret = ytable_add_attrib(&ytable, NULL, "f", 1)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = ytable_add_attrib(&ytable, NULL, "f", 1)) != CL_SUCCESS) {
cli_warnmsg("load_oneyara: failed to add 'fullword' sigopt\n");
str_error++;
break;
@ -3832,7 +3832,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
target_str = cli_strdup(YARATARGET0);
memset(&tdb, 0, sizeof(tdb));
if ((ret = init_tdb(&tdb, engine, target_str, newident)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = init_tdb(&tdb, engine, target_str, newident)) != CL_SUCCESS) {
ytable_delete(&ytable);
free(logic);
free(target_str);
@ -3914,7 +3914,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
(ytable.table[i]->sigopts & ACPATT_OPTION_WIDE) ? "w" : "",
(ytable.table[i]->sigopts & ACPATT_OPTION_ASCII) ? "a" : "");
if ((ret = cli_sigopts_handler(root, newident, ytable.table[i]->hexstr, ytable.table[i]->sigopts, 0, 0, ytable.table[i]->offset, target, lsigid, options)) != CL_SUCCESS) {
if (CL_SUCCESS != (ret = cli_sigopts_handler(root, newident, ytable.table[i]->hexstr, ytable.table[i]->sigopts, 0, 0, ytable.table[i]->offset, target, lsigid, options)) != CL_SUCCESS) {
root->ac_lsigs--;
FREE_TDB(tdb);
ytable_delete(&ytable);
@ -3943,7 +3943,7 @@ struct _yara_global {
YR_HASH_TABLE *db_table;
};
int cli_yara_init(struct cl_engine *engine)
cl_error_t cli_yara_init(struct cl_engine *engine)
{
/* Initialize YARA */
engine->yara_global = cli_calloc(1, sizeof(struct _yara_global));
@ -4303,7 +4303,7 @@ static int cli_loadpwdb(FILE *fs, struct cl_engine *engine, unsigned int options
static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned int *signo, unsigned int options);
int cli_load(const char *filename, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio)
cl_error_t cli_load(const char *filename, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio)
{
FILE *fs = NULL;
int ret = CL_SUCCESS;
@ -4739,11 +4739,11 @@ int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, uns
}
if ((dboptions & CL_DB_PHISHING_URLS) && !engine->phishcheck && (engine->dconf->phishing & PHISHING_CONF_ENGINE))
if ((ret = phishing_init(engine)))
if (CL_SUCCESS != (ret = phishing_init(engine)))
return ret;
if ((dboptions & CL_DB_BYTECODE) && !engine->bcs.inited) {
if ((ret = cli_bytecode_init(&engine->bcs)))
if (CL_SUCCESS != (ret = cli_bytecode_init(&engine->bcs)))
return ret;
} else {
cli_dbgmsg("Bytecode engine disabled\n");

@ -116,18 +116,18 @@
char *cli_virname(const char *virname, unsigned int official);
int cli_sigopts_handler(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options);
cl_error_t cli_sigopts_handler(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options);
int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options);
cl_error_t cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options);
int cli_load(const char *filename, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio);
cl_error_t cli_load(const char *filename, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio);
char *cli_dbgets(char *buff, unsigned int size, FILE *fs, struct cli_dbio *dbio);
int cli_initroots(struct cl_engine *engine, unsigned int options);
cl_error_t cli_initroots(struct cl_engine *engine, unsigned int options);
#ifdef HAVE_YARA
int cli_yara_init(struct cl_engine *engine);
cl_error_t cli_yara_init(struct cl_engine *engine);
void cli_yara_free(struct cl_engine *engine);
#endif

@ -60,8 +60,8 @@
/* Prototypes */
static regex_t *new_preg(struct regex_matcher *matcher);
static size_t reverse_string(char *pattern);
static int add_pattern_suffix(void *cbdata, const char *suffix, size_t suffix_len, const struct regex_list *regex);
static int add_static_pattern(struct regex_matcher *matcher, char *pattern);
static cl_error_t add_pattern_suffix(void *cbdata, const char *suffix, size_t suffix_len, const struct regex_list *regex);
static cl_error_t add_static_pattern(struct regex_matcher *matcher, char *pattern);
/* ---------- */
#define MATCH_SUCCESS 0
@ -148,18 +148,26 @@ static int validate_subdomain(const struct regex_list *regex, const struct pre_f
* Do not send NULL pointers to this function!!
*
*/
int regex_list_match(struct regex_matcher *matcher, char *real_url, const char *display_url, const struct pre_fixup_info *pre_fixup, int hostOnly, const char **info, int is_whitelist)
cl_error_t regex_list_match(struct regex_matcher *matcher, char *real_url, const char *display_url, const struct pre_fixup_info *pre_fixup, int hostOnly, const char **info, int is_whitelist)
{
char *orig_real_url = real_url;
struct regex_list *regex;
size_t real_len, display_len, buffer_len;
char *buffer = NULL;
char *bufrev = NULL;
cl_error_t rc = CL_SUCCESS;
int filter_search_rc = 0;
int root;
struct cli_ac_data mdata;
struct cli_ac_result *res = NULL;
assert(matcher);
assert(real_url);
assert(display_url);
*info = NULL;
if (!matcher->list_inited)
return 0;
return CL_SUCCESS;
assert(matcher->list_built);
/* skip initial '.' inserted by get_host */
if (real_url[0] == '.') real_url++;
@ -169,98 +177,95 @@ int regex_list_match(struct regex_matcher *matcher, char *real_url, const char *
buffer_len = (hostOnly && !is_whitelist) ? real_len + 1 : real_len + display_len + 1 + 1;
if (buffer_len < 3) {
/* too short, no match possible */
return 0;
return CL_SUCCESS;
}
buffer = cli_malloc(buffer_len + 1);
if (!buffer) {
cli_errmsg("regex_list_match: Unable to allocate memory for buffer\n");
return CL_EMEM;
}
{
char *buffer = cli_malloc(buffer_len + 1);
char *bufrev;
int rc = 0, root;
struct cli_ac_data mdata;
struct cli_ac_result *res = NULL;
if (!buffer) {
cli_errmsg("regex_list_match: Unable to allocate memory for buffer\n");
return CL_EMEM;
}
strncpy(buffer, real_url, real_len);
buffer[real_len] = (!is_whitelist && hostOnly) ? '/' : ':';
strncpy(buffer, real_url, real_len);
buffer[real_len] = (!is_whitelist && hostOnly) ? '/' : ':';
/*
* For H-type PDB signatures, real_url is actually the DisplayedHostname.
* RealHostname is not used.
*/
if (!hostOnly || is_whitelist) {
/* For all other PDB and WDB signatures concatenate Real:Displayed. */
strncpy(buffer + real_len + 1, display_url, display_len);
}
buffer[buffer_len - 1] = '/';
buffer[buffer_len] = 0;
cli_dbgmsg("Looking up in regex_list: %s\n", buffer);
/* For H-type PDB signatures, real_url is actually the DisplayedHostname.
RealHostname is not used. */
if (!hostOnly || is_whitelist) {
/* For all other PDB and WDB signatures concatenate Real:Displayed. */
strncpy(buffer + real_len + 1, display_url, display_len);
}
buffer[buffer_len - 1] = '/';
buffer[buffer_len] = 0;
cli_dbgmsg("Looking up in regex_list: %s\n", buffer);
if (CL_SUCCESS != (rc = cli_ac_initdata(&mdata, 0, 0, 0, CLI_DEFAULT_AC_TRACKLEN)))
return rc;
if ((rc = cli_ac_initdata(&mdata, 0, 0, 0, CLI_DEFAULT_AC_TRACKLEN)))
return rc;
bufrev = cli_strdup(buffer);
if (!bufrev)
return CL_EMEM;
bufrev = cli_strdup(buffer);
if (!bufrev)
return CL_EMEM;
reverse_string(bufrev);
rc = filter_search(&matcher->filter, (const unsigned char *)bufrev, buffer_len) != -1;
if (rc == -1) {
free(buffer);
free(bufrev);
/* filter says this suffix doesn't match.
reverse_string(bufrev);
filter_search_rc = filter_search(&matcher->filter, (const unsigned char *)bufrev, buffer_len) != -1;
if (filter_search_rc == -1) {
free(buffer);
free(bufrev);
/* filter says this suffix doesn't match.
* The filter has false positives, but no false
* negatives */
return 0;
return CL_SUCCESS;
}
rc = cli_ac_scanbuff((const unsigned char *)bufrev, buffer_len, NULL, (void *)&regex, &res, &matcher->suffixes, &mdata, 0, 0, NULL, AC_SCAN_VIR, NULL);
free(bufrev);
cli_ac_freedata(&mdata);
rc = CL_SUCCESS;
root = matcher->root_regex_idx;
while (res || root) {
struct cli_ac_result *q;
if (!res) {
regex = matcher->suffix_regexes[root].head;
root = 0;
} else {
regex = res->customdata;
}
rc = cli_ac_scanbuff((const unsigned char *)bufrev, buffer_len, NULL, (void *)&regex, &res, &matcher->suffixes, &mdata, 0, 0, NULL, AC_SCAN_VIR, NULL);
free(bufrev);
cli_ac_freedata(&mdata);
rc = 0;
root = matcher->root_regex_idx;
while (res || root) {
struct cli_ac_result *q;
if (!res) {
regex = matcher->suffix_regexes[root].head;
root = 0;
} else {
regex = res->customdata;
}
while (!rc && regex) {
/* loop over multiple regexes corresponding to
while (!rc && regex) {
/* loop over multiple regexes corresponding to
* this suffix */
if (!regex->preg) {
/* we matched a static pattern */
rc = validate_subdomain(regex, pre_fixup, buffer, buffer_len, real_url, real_len, orig_real_url);
} else {
rc = !cli_regexec(regex->preg, buffer, 0, NULL, 0);
}
if (rc) *info = regex->pattern;
regex = regex->nxt;
}
if (res) {
q = res;
res = res->next;
free(q);
if (!regex->preg) {
/* we matched a static pattern */
rc = validate_subdomain(regex, pre_fixup, buffer, buffer_len, real_url, real_len, orig_real_url);
} else {
rc = !cli_regexec(regex->preg, buffer, 0, NULL, 0);
}
if (rc) *info = regex->pattern;
regex = regex->nxt;
}
if (res) {
q = res;
res = res->next;
free(q);
}
free(buffer);
if (!rc)
cli_dbgmsg("Lookup result: not in regex list\n");
else
cli_dbgmsg("Lookup result: in regex list\n");
return rc;
}
free(buffer);
if (!rc)
cli_dbgmsg("Lookup result: not in regex list\n");
else
cli_dbgmsg("Lookup result: in regex list\n");
return rc;
}
/* Initialization & loading */
/* Initializes @matcher, allocating necessary substructures */
int init_regex_list(struct regex_matcher *matcher, uint8_t dconf_prefiltering)
cl_error_t init_regex_list(struct regex_matcher *matcher, uint8_t dconf_prefiltering)
{
#ifdef USE_MPOOL
mpool_t *mp = matcher->mempool;
#endif
int rc;
cl_error_t rc;
assert(matcher);
memset(matcher, 0, sizeof(*matcher));
@ -389,9 +394,10 @@ static int add_hash(struct regex_matcher *matcher, char *pattern, const char fl,
}
/* Load patterns/regexes from file */
int load_regex_matcher(struct cl_engine *engine, struct regex_matcher *matcher, FILE *fd, unsigned int *signo, unsigned int options, int is_whitelist, struct cli_dbio *dbio, uint8_t dconf_prefiltering)
cl_error_t load_regex_matcher(struct cl_engine *engine, struct regex_matcher *matcher, FILE *fd, unsigned int *signo, unsigned int options, int is_whitelist, struct cli_dbio *dbio, uint8_t dconf_prefiltering)
{
int rc, line = 0, entry = 0;
cl_error_t rc;
int line = 0, entry = 0;
char buffer[FILEBUFF];
assert(matcher);
@ -505,9 +511,9 @@ int load_regex_matcher(struct cl_engine *engine, struct regex_matcher *matcher,
}
/* Build the matcher list */
int cli_build_regex_list(struct regex_matcher *matcher)
cl_error_t cli_build_regex_list(struct regex_matcher *matcher)
{
int rc;
cl_error_t rc;
if (!matcher)
return CL_SUCCESS;
if (!matcher->list_inited || !matcher->list_loaded) {
@ -624,7 +630,7 @@ static void list_add_tail(struct regex_list_ht *ht, struct regex_list *regex)
}
/* returns 0 on success, clamav error code otherwise */
static int add_pattern_suffix(void *cbdata, const char *suffix, size_t suffix_len, const struct regex_list *iregex)
static cl_error_t add_pattern_suffix(void *cbdata, const char *suffix, size_t suffix_len, const struct regex_list *iregex)
{
struct regex_matcher *matcher = cbdata;
struct regex_list *regex = cli_malloc(sizeof(*regex));
@ -663,7 +669,7 @@ static int add_pattern_suffix(void *cbdata, const char *suffix, size_t suffix_le
matcher->root_regex_idx = n;
add_newsuffix(matcher, regex, suffix, suffix_len);
}
return 0;
return CL_SUCCESS;
}
static size_t reverse_string(char *pattern)
@ -695,11 +701,11 @@ static regex_t *new_preg(struct regex_matcher *matcher)
return r;
}
static int add_static_pattern(struct regex_matcher *matcher, char *pattern)
static cl_error_t add_static_pattern(struct regex_matcher *matcher, char *pattern)
{
size_t len;
struct regex_list regex;
int rc;
cl_error_t rc;
len = reverse_string(pattern);
regex.nxt = NULL;
@ -710,9 +716,9 @@ static int add_static_pattern(struct regex_matcher *matcher, char *pattern)
return rc;
}
int regex_list_add_pattern(struct regex_matcher *matcher, char *pattern)
cl_error_t regex_list_add_pattern(struct regex_matcher *matcher, char *pattern)
{
int rc;
cl_error_t rc;
regex_t *preg;
size_t len;
/* we only match the host, so remove useless stuff */

@ -58,11 +58,11 @@ struct regex_matcher {
int list_built : 2;
};
int cli_build_regex_list(struct regex_matcher* matcher);
int regex_list_add_pattern(struct regex_matcher* matcher, char* pattern);
int regex_list_match(struct regex_matcher* matcher, char* real_url, const char* display_url, const struct pre_fixup_info* pre_fixup, int hostOnly, const char** info, int is_whitelist);
int init_regex_list(struct regex_matcher* matcher, uint8_t dconf_prefiltering);
int load_regex_matcher(struct cl_engine* engine, struct regex_matcher* matcher, FILE* fd, unsigned int* signo, unsigned int options, int is_whitelist, struct cli_dbio* dbio, uint8_t dconf_prefiltering);
cl_error_t cli_build_regex_list(struct regex_matcher* matcher);
cl_error_t regex_list_add_pattern(struct regex_matcher* matcher, char* pattern);
cl_error_t regex_list_match(struct regex_matcher* matcher, char* real_url, const char* display_url, const struct pre_fixup_info* pre_fixup, int hostOnly, const char** info, int is_whitelist);
cl_error_t init_regex_list(struct regex_matcher* matcher, uint8_t dconf_prefiltering);
cl_error_t load_regex_matcher(struct cl_engine* engine, struct regex_matcher* matcher, FILE* fd, unsigned int* signo, unsigned int options, int is_whitelist, struct cli_dbio* dbio, uint8_t dconf_prefiltering);
void regex_list_cleanup(struct regex_matcher* matcher);
void regex_list_done(struct regex_matcher* matcher);
int is_regex_ok(struct regex_matcher* matcher);

@ -53,7 +53,7 @@ void cli_pcre_free(void *ptr, void *ext)
#endif
/* cli_pcre_init_internal: redefine pcre_malloc and pcre_free; pcre2 does this during compile */
int cli_pcre_init_internal()
cl_error_t cli_pcre_init_internal()
{
#if !USING_PCRE2
pcre_malloc = cli_malloc;
@ -65,7 +65,7 @@ int cli_pcre_init_internal()
return CL_SUCCESS;
}
int cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout)
cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout)
{
if (!pd || !opt || !(*opt))
return CL_ENULLARG;
@ -135,7 +135,7 @@ int cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout)
}
#if USING_PCRE2
int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override)
cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override)
{
int errornum;
PCRE2_SIZE erroffset;
@ -193,7 +193,7 @@ int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, l
return CL_SUCCESS;
}
#else
int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override)
cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override)
{
const char *error;
int erroffset;
@ -442,7 +442,7 @@ void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer
}
}
int cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd)
cl_error_t cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd)
{
results->err = CL_SUCCESS;
results->match[0] = results->match[1] = 0;

@ -76,13 +76,13 @@ struct cli_pcre_results {
};
#endif
int cli_pcre_init_internal();
int cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout);
int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override);
cl_error_t cli_pcre_init_internal();
cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout);
cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override);
int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int override_offset, int options, struct cli_pcre_results *results);
void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int rc, struct cli_pcre_results *results);
int cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd);
cl_error_t cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd);
void cli_pcre_results_free(struct cli_pcre_results *results);
void cli_pcre_free_single(struct cli_pcre_data *pd);
#endif /* HAVE_PCRE */

@ -59,7 +59,7 @@ struct node {
};
/* --- Prototypes --*/
static int build_suffixtree_descend(struct node *n, struct text_buffer *buf, suffix_callback cb, void *cbdata, struct regex_list *regex);
static cl_error_t build_suffixtree_descend(struct node *n, struct text_buffer *buf, suffix_callback cb, void *cbdata, struct regex_list *regex);
/* -----------------*/
static uint8_t dot_bitmap[32] = {
@ -324,7 +324,7 @@ static struct node *parse_regex(const char *p, size_t *last)
#define BITMAP_HASSET(b, i) (b[i >> 3] & (1 << (i & 7)))
static int build_suffixtree_ascend(struct node *n, struct text_buffer *buf, struct node *prev, suffix_callback cb, void *cbdata, struct regex_list *regex)
static cl_error_t build_suffixtree_ascend(struct node *n, struct text_buffer *buf, struct node *prev, suffix_callback cb, void *cbdata, struct regex_list *regex)
{
size_t i, cnt;
while (n) {
@ -334,7 +334,7 @@ static int build_suffixtree_ascend(struct node *n, struct text_buffer *buf, stru
textbuffer_putc(buf, '\0');
if (cb(cbdata, buf->data, buf->pos - 1, regex) < 0)
return CL_EMEM;
return 0;
return CL_SUCCESS;
case leaf:
textbuffer_putc(buf, n->u.leaf_char);
n = n->parent;
@ -348,7 +348,7 @@ static int build_suffixtree_ascend(struct node *n, struct text_buffer *buf, stru
textbuffer_putc(buf, '\0');
if (cb(cbdata, buf->data, buf->pos - 1, regex) < 0)
return CL_EMEM;
return 0;
return CL_SUCCESS;
}
/* handle small classes by expanding */
for (i = 0; i < 255; i++) {
@ -368,7 +368,7 @@ static int build_suffixtree_ascend(struct node *n, struct text_buffer *buf, stru
return CL_EMEM;
/* we're done here, descend will call
* ascend if needed */
return 0;
return CL_SUCCESS;
} else {
n = n->parent;
}
@ -380,21 +380,21 @@ static int build_suffixtree_ascend(struct node *n, struct text_buffer *buf, stru
textbuffer_putc(buf, '\0');
if (cb(cbdata, buf->data, buf->pos - 1, regex) < 0)
return CL_EMEM;
return 0;
return CL_SUCCESS;
}
prev = q;
}
return 0;
return CL_SUCCESS;
}
static int build_suffixtree_descend(struct node *n, struct text_buffer *buf, suffix_callback cb, void *cbdata, struct regex_list *regex)
static cl_error_t build_suffixtree_descend(struct node *n, struct text_buffer *buf, suffix_callback cb, void *cbdata, struct regex_list *regex)
{
size_t pos;
while (n && n->type == concat) {
n = n->u.children.right;
}
if (!n)
return 0;
return CL_SUCCESS;
/* find out end of the regular expression,
* if it ends with a static pattern */
switch (n->type) {
@ -412,19 +412,19 @@ static int build_suffixtree_descend(struct node *n, struct text_buffer *buf, suf
textbuffer_putc(buf, '\0');
if (cb(cbdata, buf->data, buf->pos - 1, regex) < 0)
return CL_EMEM;
return 0;
return CL_SUCCESS;
case leaf:
case leaf_class:
if (build_suffixtree_ascend(n, buf, NULL, cb, cbdata, regex) < 0)
return CL_EMEM;
return 0;
return CL_SUCCESS;
default:
break;
}
return 0;
return CL_SUCCESS;
}
int cli_regex2suffix(const char *pattern, regex_t *preg, suffix_callback cb, void *cbdata)
cl_error_t cli_regex2suffix(const char *pattern, regex_t *preg, suffix_callback cb, void *cbdata)
{
struct regex_list regex;
struct text_buffer buf;

@ -30,5 +30,5 @@ struct regex_list {
struct regex_list *nxt;
};
typedef int (*suffix_callback)(void *cbdata, const char *suffix, size_t len, const struct regex_list *regex);
int cli_regex2suffix(const char *pattern, regex_t *preg, suffix_callback cb, void *cbdata);
cl_error_t cli_regex2suffix(const char *pattern, regex_t *preg, suffix_callback cb, void *cbdata);
#endif

@ -199,7 +199,6 @@ static int cli_scandir(const char *dirname, cli_ctx *ctx)
static cl_error_t cli_unrar_scanmetadata(unrar_metadata_t *metadata, cli_ctx *ctx, unsigned int files)
{
cl_error_t status = CL_CLEAN;
int virus_found = 0;
cli_dbgmsg("RAR: %s, crc32: 0x%x, encrypted: %u, compressed: %u, normal: %u, method: %u, ratio: %u\n",
metadata->filename, metadata->crc, metadata->encrypted, (unsigned int)metadata->pack_size,
@ -213,8 +212,6 @@ static cl_error_t cli_unrar_scanmetadata(unrar_metadata_t *metadata, cli_ctx *ct
status = CL_EUNPACK;
}
done:
return status;
}
@ -224,7 +221,6 @@ static cl_error_t cli_scanrar(const char *filepath, int desc, cli_ctx *ctx)
cl_unrar_error_t unrar_ret = UNRAR_ERR;
char *extract_dir = NULL; /* temp dir to write extracted files to */
char *comment_dir = NULL; /* temp dir to write file comments to */
unsigned int file_count = 0;
unsigned int viruses_found = 0;
@ -2789,7 +2785,6 @@ static int cli_scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_file_
{
int ret = CL_CLEAN, nret = CL_CLEAN;
struct cli_matched_type *ftoffset = NULL, *fpt;
uint32_t lastrar;
struct cli_exe_info peinfo;
unsigned int acmode = AC_SCAN_VIR, break_loop = 0;
fmap_t *map = *ctx->fmap;

@ -317,7 +317,6 @@ static int unz(const uint8_t *src, uint32_t csize, uint32_t usize, uint16_t meth
static inline void zupdatekey(uint32_t key[3], unsigned char input)
{
unsigned char tmp[1];
unsigned long crctmp;
tmp[0] = input;
ZIP_CRC32(key[0], key[0], tmp, 1);

@ -1569,7 +1569,9 @@ primary_expression
}
| _TEXT_STRING_
{
#if REAL_YARA
SIZED_STRING* sized_string = $1;
#endif
char* string = NULL;
#if REAL_YARA

@ -720,6 +720,8 @@ int yr_lex_parse_rules_string(
return compiler->errors;
#else
(void)rules_string;
(void)compiler;
cli_errmsg("yara_lexer:yr_lex_parse_rules_string() disabled\n");
return 0;
#endif

@ -295,8 +295,15 @@ int _yr_parser_write_string(
#endif
int result;
#if REAL_YARA
int max_string_len;
int free_literal = FALSE;
#endif
#if !REAL_YARA
UNUSEDPARAM(re);
UNUSEDPARAM(min_atom_length);
#endif
*string = NULL;
@ -456,23 +463,21 @@ YR_STRING* yr_parser_reduce_string_declaration(
SIZED_STRING* str)
{
int min_atom_length;
int min_atom_length_aux;
int re_flags = 0;
int32_t min_gap;
int32_t max_gap;
char message[512];
YR_COMPILER* compiler = yyget_extra(yyscanner);
YR_STRING* string = NULL;
#if REAL_YARA
int min_atom_length_aux;
char message[512];
int32_t min_gap;
int32_t max_gap;
YR_STRING* aux_string;
YR_STRING* prev_string;
RE* re = NULL;
RE* remainder_re;
#if REAL_YARA
RE_ERROR re_error;
#endif
@ -655,6 +660,12 @@ YR_STRING* yr_parser_reduce_string_declaration(
YR_STRING* string;
uint8_t halt = OP_HALT;
#if !REAL_YARA
UNUSEDPARAM(tags);
UNUSEDPARAM(strings);
UNUSEDPARAM(metas);
#endif
if (yr_hash_table_lookup(
compiler->rules_table,
identifier,
@ -899,12 +910,13 @@ YR_STRING* yr_parser_reduce_string_declaration(
yyscan_t yyscanner,
SIZED_STRING * module_name)
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
/// YR_OBJECT* module_structure;
#if REAL_YARA
YR_COMPILER* compiler = NULL;
/// YR_OBJECT* module_structure;
char* name;
compiler = yyget_extra(yyscanner);
module_structure = yr_hash_table_lookup(
compiler->objects_table,
module_name->c_string,
@ -952,6 +964,9 @@ YR_STRING* yr_parser_reduce_string_declaration(
return compiler->last_result;
#else
UNUSEDPARAM(yyscanner);
UNUSEDPARAM(module_name);
return ERROR_SUCCESS;
#endif
}

@ -18,16 +18,23 @@
* MA 02110-1301, USA.
*/
#include "shared/misc.h"
#include "shared/output.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "clamav.h"
#include "shared/misc.h"
#include "shared/output.h"
#ifndef PRELUDE
void prelude_logging(const char *filename, const char *virname, const char *virhash, int virsize)
{
UNUSEDPARAM(filename);
UNUSEDPARAM(virname);
UNUSEDPARAM(virhash);
UNUSEDPARAM(virsize);
logg("You have to compile with libprelude using ./configure --enable-prelude\n");
}
#else

@ -188,9 +188,9 @@ const struct clam_option __clam_options[] = {
/* config file/cmdline options */
{"AlertExceedsMax", "alert-exceeds-max", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_CLAMSCAN, "", ""},
{"PreludeEnable", "prelude-enable", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD, "Enable prelude"},
{"PreludeEnable", "prelude-enable", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD, "Enable prelude", ""},
{"PreludeAnalyzerName", "prelude-analyzer-name", 0, CLOPT_TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD, "Name of the analyzer as seen in prewikka"},
{"PreludeAnalyzerName", "prelude-analyzer-name", 0, CLOPT_TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD, "Name of the analyzer as seen in prewikka", ""},
{"LogFile", "log", 'l', CLOPT_TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN | OPT_CLAMDSCAN, "Save all reports to a log file.", "/tmp/clamav.log"},

@ -2368,7 +2368,7 @@ inline static char *get_paren_end(char *hexstr)
static char *decodehexspecial(const char *hex, unsigned int *dlen)
{
char *pt, *start, *hexcpy, *decoded, *h, *e, *c, op, lop;
unsigned int i, len = 0, hlen, negative;
unsigned int len = 0, hlen, negative;
int level;
char *buff;
@ -2806,7 +2806,7 @@ static int decodehex(const char *hexsig)
static int decodesigmod(const char *sigmod)
{
int i;
size_t i;
for (i = 0; i < strlen(sigmod); i++) {
mprintf(" ");
@ -2836,9 +2836,7 @@ static int decodesigmod(const char *sigmod)
static int decodecdb(char **tokens)
{
char *pt = NULL;
int sz = 0;
int sz = 0;
char *range[2];
if (!tokens)

Loading…
Cancel
Save