Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Jul 10, 2024
1 parent 7693070 commit 7243032
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
42 changes: 22 additions & 20 deletions libclamav/htmlnorm.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,19 @@ void html_tag_arg_add(tag_arguments_t *tags,
const char *tag, char *value)
{
int len, i;
int tagCnt = tags->count;
int valueCnt = tags->count;
int contentCnt = 0;
unsigned char ** tmp = NULL;
int tagCnt = tags->count;
int valueCnt = tags->count;
int contentCnt = 0;
unsigned char **tmp = NULL;

tmp = (unsigned char **) cli_max_realloc(tags->tag, (tagCnt+1) * sizeof(char *));
tmp = (unsigned char **)cli_max_realloc(tags->tag, (tagCnt + 1) * sizeof(char *));
if (!tmp) {
goto done;
}
tags->tag = tmp;
tagCnt++;

tmp = (unsigned char **)cli_max_realloc(tags->value, (valueCnt+1) * sizeof(char *));
tmp = (unsigned char **)cli_max_realloc(tags->value, (valueCnt + 1) * sizeof(char *));
if (!tmp) {
goto done;
}
Expand All @@ -391,11 +391,11 @@ void html_tag_arg_add(tag_arguments_t *tags,

if (tags->scanContents) {
contentCnt = tags->count;
tmp = (unsigned char **)cli_max_realloc(tags->contents, (contentCnt+1) * sizeof(*tags->contents));
tmp = (unsigned char **)cli_max_realloc(tags->contents, (contentCnt + 1) * sizeof(*tags->contents));
if (!tmp) {
goto done;
}
tags->contents = tmp;
tags->contents = tmp;
tags->contents[contentCnt] = NULL;
contentCnt++;
}
Expand All @@ -407,7 +407,7 @@ void html_tag_arg_add(tag_arguments_t *tags,
if (NULL == tags->value[tags->count]) {
goto done;
}
len = strlen((const char *)value + 1);
len = strlen((const char *)value + 1);
if (len > 0) {
tags->value[tags->count][len - 1] = '\0';
}
Expand Down Expand Up @@ -668,10 +668,11 @@ static void js_process(struct parser_state *js_state, const unsigned char *js_be
}
}

bool html_insert_form_data(const char * const value, form_data_t *tags) {
bool bRet = false;
bool html_insert_form_data(const char *const value, form_data_t *tags)
{
bool bRet = false;
size_t cnt = tags->count + 1;
char ** tmp = NULL;
char **tmp = NULL;

/*
* Do NOT use cli_max_realloc_or_free because all the previously malloc'd tag
Expand All @@ -690,22 +691,23 @@ bool html_insert_form_data(const char * const value, form_data_t *tags) {

bRet = true;
done:
if (!bRet){
if (!bRet) {
memset(tags, 0, sizeof(*tags));
}

return bRet;
}

void html_form_data_tag_free(form_data_t *tags) {
void html_form_data_tag_free(form_data_t *tags)
{
size_t i;
for (i = 0; i < tags->count; i++){
for (i = 0; i < tags->count; i++) {
CLI_FREE_AND_SET_NULL(tags->urls[i]);
}
CLI_FREE_AND_SET_NULL(tags->urls);
}

static bool cli_html_normalise(cli_ctx *ctx, int fd, m_area_t *m_area, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t * form_data)
static bool cli_html_normalise(cli_ctx *ctx, int fd, m_area_t *m_area, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t *form_data)
{
int fd_tmp, tag_length = 0, tag_arg_length = 0;
bool binary, retval = false, escape = false, hex = false;
Expand Down Expand Up @@ -1371,8 +1373,8 @@ static bool cli_html_normalise(cli_ctx *ctx, int fd, m_area_t *m_area, const cha
free(in_form_action);
}
in_form_action = (unsigned char *)cli_safer_strdup(arg_action_value);
if (form_data){
html_insert_form_data((const char * const) in_form_action, form_data);
if (form_data) {
html_insert_form_data((const char *const)in_form_action, form_data);
}
}
} else if (strcmp(tag, "img") == 0) {
Expand Down Expand Up @@ -2026,7 +2028,7 @@ bool html_normalise_mem(cli_ctx *ctx, unsigned char *in_buff, off_t in_size, con
return html_normalise_mem_form_data(ctx, in_buff, in_size, dirname, hrefs, dconf, NULL);
}

bool html_normalise_mem_form_data(cli_ctx *ctx, unsigned char *in_buff, off_t in_size, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t * form_data)
bool html_normalise_mem_form_data(cli_ctx *ctx, unsigned char *in_buff, off_t in_size, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t *form_data)
{
m_area_t m_area;

Expand All @@ -2043,7 +2045,7 @@ bool html_normalise_map(cli_ctx *ctx, fmap_t *map, const char *dirname, tag_argu
return html_normalise_map_form_data(ctx, map, dirname, hrefs, dconf, NULL);
}

bool html_normalise_map_form_data(cli_ctx *ctx, fmap_t *map, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t * form_data)
bool html_normalise_map_form_data(cli_ctx *ctx, fmap_t *map, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t *form_data)
{
bool retval = false;
m_area_t m_area;
Expand Down
6 changes: 3 additions & 3 deletions libclamav/htmlnorm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ typedef struct m_area_tag {
} m_area_t;

typedef struct form_data_tag {
char ** urls;
char **urls;
size_t count;
} form_data_t;

bool html_normalise_mem(cli_ctx *ctx, unsigned char *in_buff, off_t in_size, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf);
bool html_normalise_mem_form_data(cli_ctx *ctx, unsigned char *in_buff, off_t in_size, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t * form_data);
bool html_normalise_mem_form_data(cli_ctx *ctx, unsigned char *in_buff, off_t in_size, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t *form_data);
bool html_normalise_map(cli_ctx *ctx, fmap_t *map, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf);
bool html_normalise_map_form_data(cli_ctx *ctx, fmap_t *map, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t * form_data);
bool html_normalise_map_form_data(cli_ctx *ctx, fmap_t *map, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf *dconf, form_data_t *form_data);
void html_tag_arg_free(tag_arguments_t *tags);
bool html_screnc_decode(fmap_t *map, const char *dirname);
void html_tag_arg_add(tag_arguments_t *tags, const char *tag, char *value);
Expand Down
17 changes: 7 additions & 10 deletions libclamav/scanners.c
Original file line number Diff line number Diff line change
Expand Up @@ -2491,9 +2491,9 @@ static bool is_url(const char *const str)
return bRet;
#undef MATCH
}
static void save_urls(cli_ctx *ctx, tag_arguments_t *hrefs, form_data_t * form_data)
static void save_urls(cli_ctx *ctx, tag_arguments_t *hrefs, form_data_t *form_data)
{
int i = 0;
int i = 0;
json_object *ary = NULL;

if (NULL == hrefs) {
Expand All @@ -2511,9 +2511,9 @@ static void save_urls(cli_ctx *ctx, tag_arguments_t *hrefs, form_data_t * form_d
/*Add hrefs*/
for (i = 0; i < hrefs->count; i++) {
if (is_url((const char *)hrefs->value[i])) {
if (NULL == ary){
if (NULL == ary) {
ary = cli_jsonarray(ctx->wrkproperty, HTML_URLS_JSON_KEY);
if (!ary){
if (!ary) {
cli_dbgmsg("[cli_scanhtml] Failed to add \"%s\" entry JSON array\n", HTML_URLS_JSON_KEY);
return;
}
Expand All @@ -2523,11 +2523,11 @@ static void save_urls(cli_ctx *ctx, tag_arguments_t *hrefs, form_data_t * form_d
}

/*Add form_data*/
for (i = 0; i < (int) form_data->count; i++) {
for (i = 0; i < (int)form_data->count; i++) {
if (is_url((const char *)form_data->urls[i])) {
if (NULL == ary){
if (NULL == ary) {
ary = cli_jsonarray(ctx->wrkproperty, HTML_URLS_JSON_KEY);
if (!ary){
if (!ary) {
cli_dbgmsg("[cli_scanhtml] Failed to add \"%s\" entry JSON array\n", HTML_URLS_JSON_KEY);
return;
}
Expand All @@ -2536,7 +2536,6 @@ static void save_urls(cli_ctx *ctx, tag_arguments_t *hrefs, form_data_t * form_d
}
}


#if 0
if (!bAdded) {
return;
Expand All @@ -2553,8 +2552,6 @@ static void save_urls(cli_ctx *ctx, tag_arguments_t *hrefs, form_data_t * form_d
cli_dbgmsg("[cli_scanhtml] Failed to add \"%s\" entry JSON array\n", HTML_URLS_JSON_KEY);
}
#endif


}

static cl_error_t cli_scanhtml(cli_ctx *ctx)
Expand Down

0 comments on commit 7243032

Please sign in to comment.