summaryrefslogtreecommitdiffstats
path: root/plugin/eurephiadb_session.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/eurephiadb_session.c')
-rw-r--r--plugin/eurephiadb_session.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/plugin/eurephiadb_session.c b/plugin/eurephiadb_session.c
index d6cd2b2..aca3b28 100644
--- a/plugin/eurephiadb_session.c
+++ b/plugin/eurephiadb_session.c
@@ -84,12 +84,10 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest,
DEBUG(ctx, 12, "Function call: eDBopen_session_seed(ctx, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
digest, cname, username, vpnipaddr, vpnipmask, remipaddr, remport);
- new_session = (eurephiaSESSION *) malloc(sizeof(eurephiaSESSION) + 2);
+ new_session = (eurephiaSESSION *) malloc_nullsafe(ctx, sizeof(eurephiaSESSION) + 2);
if( new_session == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0, "Could not allocate memory for a new session");
return NULL;
}
- memset(new_session, 0, sizeof(eurephiaSESSION) + 2);
// Session type is stSESSION if we do have VPN address and/or netmask
new_session->type = ((vpnipaddr == NULL) && (vpnipmask == NULL) ? stAUTHENTICATION : stSESSION);
@@ -99,13 +97,11 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest,
+ strlen_nullsafe(vpnipaddr) + strlen_nullsafe(vpnipmask) + strlen_nullsafe(remipaddr)
+ strlen_nullsafe(remport) + 20; // +5 == len(pid) + 15 extra buffer if some strings are (null)
- seeddata = (char *) malloc((totlen * 2) + 4);
+ seeddata = (char *) malloc_nullsafe(ctx, (totlen * 2) + 4);
if( seeddata == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0, "Could not allocate memory for a new session key (1)");
free_nullsafe(new_session);
return NULL;
}
- memset(seeddata, 0, (totlen * 2) + 4);
snprintf((char *)seeddata, totlen,
"%s%s%s%s%s%s%s%i", digest, cname, username, vpnipaddr, vpnipmask, remipaddr, remport,getpid());
@@ -116,14 +112,12 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest,
SHA512Update(&sha, seeddata, totlen);
SHA512Final(&sha, sha_res);
- seed = (char *) malloc((SHA512_HASH_SIZE*2)+3);
+ seed = (char *) malloc_nullsafe(ctx, (SHA512_HASH_SIZE*2)+3);
if( seed == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0, "Could not allocate memory for session seed");
free_nullsafe(seeddata);
free_nullsafe(new_session);
return NULL;
}
- memset(seed, 0, (SHA512_HASH_SIZE*2)+2);
ptr = seed;
for( i = 0; i < SHA512_HASH_SIZE; i++ ) {
@@ -147,9 +141,8 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest,
DEBUG(ctx, 13, "Unknown session seed, creating new session key");
// Loop until we get a unique sessionkey - don't loop more than 10 times
- skeydata = (char *) malloc((totlen*2)+4);
+ skeydata = (char *) malloc_nullsafe(ctx, (totlen*2)+4);
if( skeydata == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0, "Could not allocate memory for new session key data");
free_nullsafe(new_session->sessionkey);
free_nullsafe(new_session);
free_nullsafe(seeddata);
@@ -162,17 +155,14 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest,
// FIXME: Validate that we have enough random data for the session key
// Append some random data to our session seed
- rndstr = (char *) malloc((totlen * 2));
+ rndstr = (char *) malloc_nullsafe(ctx, (totlen * 2));
if( rndstr == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0,
- "Could not allocate memory for new session key data (2)");
free_nullsafe(new_session->sessionkey);
free_nullsafe(new_session);
free_nullsafe(seeddata);
free_nullsafe(seed);
return NULL;
}
- memset(rndstr, 0, (totlen * 2));
rndlen = ((totlen * 2) - strlen_nullsafe(seed) - 2);
if( !eurephia_randstring(ctx, rndstr, rndlen) ) {
@@ -191,16 +181,13 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest,
SHA512Final(&sha, sha_res);
free_nullsafe(new_session->sessionkey);
- new_session->sessionkey = (char *) malloc((SHA512_HASH_SIZE*2)+3);
+ new_session->sessionkey = (char *) malloc_nullsafe(ctx, (SHA512_HASH_SIZE*2)+3);
if( new_session->sessionkey == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0,
- "Could not allocate memory for new session key");
free_nullsafe(new_session);
free_nullsafe(seeddata);
free_nullsafe(seed);
return NULL;
}
- memset(new_session->sessionkey, 0, (SHA512_HASH_SIZE*2)+3);
ptr = new_session->sessionkey;
for( i = 0; i < SHA512_HASH_SIZE; i++ ) {
@@ -268,12 +255,10 @@ eurephiaSESSION *eDBopen_session_macaddr(eurephiaCTX *ctx, const char *macaddr)
DEBUG(ctx, 12, "Function call: eDBopen_session_mac(ctx, '%s')", macaddr);
- new_session = (eurephiaSESSION *) malloc(sizeof(eurephiaSESSION) + 2);
+ new_session = (eurephiaSESSION *) malloc_nullsafe(ctx, sizeof(eurephiaSESSION) + 2);
if( new_session == NULL ) {
- eurephia_log(ctx, LOG_PANIC, 0, "Could not allocate memory for a new session");
return NULL;
}
- memset(new_session, 0, sizeof(eurephiaSESSION) + 2);
new_session->type = stSESSION; // When we have macaddr - this is a stSESSION type of session