From 9282a0fd29ab1d5363daf68bee361eadf936363d Mon Sep 17 00:00:00 2001 From: Damien Stuart Date: Sun, 14 Mar 2010 03:45:03 +0000 Subject: [PATCH] Changed to fix possible double-free bug under some circumstances. git-svn-id: file:///home/mbr/svn/fwknop/trunk@210 510a4753-2344-4c79-9c09-4d669213fbeb --- lib/fko_funcs.c | 1 + lib/fko_state.h | 2 +- server/incoming_spa.c | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/fko_funcs.c b/lib/fko_funcs.c index 6e12c5c3..8c75d67b 100644 --- a/lib/fko_funcs.c +++ b/lib/fko_funcs.c @@ -184,6 +184,7 @@ fko_new_with_data(fko_ctx_t *r_ctx, char *enc_msg, char *dec_key) if(res != FKO_SUCCESS) { fko_destroy(ctx); + *r_ctx = NULL; /* Make sure the caller ctx is null just in case */ return(res); } } diff --git a/lib/fko_state.h b/lib/fko_state.h index ea22eacc..dacc0e0e 100644 --- a/lib/fko_state.h +++ b/lib/fko_state.h @@ -80,7 +80,7 @@ typedef enum { /* Macros used for determining ctx initialization state. */ -#define CTX_INITIALIZED(ctx) (ctx->initval == FKO_CTX_INITIALIZED) +#define CTX_INITIALIZED(ctx) (ctx != NULL && ctx->initval == FKO_CTX_INITIALIZED) #endif /* FKO_STATE_H */ diff --git a/server/incoming_spa.c b/server/incoming_spa.c index ea45324c..5bdbf72a 100644 --- a/server/incoming_spa.c +++ b/server/incoming_spa.c @@ -33,7 +33,11 @@ int incoming_spa(fko_srv_options_t *opts) { - fko_ctx_t ctx; + /* Always a good idea to initialize ctx to null if it will be used + * repeatedly (especially when using fko_new_with_data(). + */ + fko_ctx_t ctx = NULL; + char *spa_ip_demark; char spa_msg_src_ip[16]; char spa_msg_remain[1024]; /* --DSS should not have arbitrary limit */ @@ -372,7 +376,9 @@ display_ctx(ctx); clean_and_bail: - fko_destroy(ctx); + if(ctx != NULL) + fko_destroy(ctx); + return(res); }