summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-07 21:10:22 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-07 21:10:22 +0200
commit66b29488a7ed5909564ed03b3e89cd0d008df09e (patch)
tree2ef1558a3c54b37b59a775f4734cb467cac183cb /plugin
parent428d4fd45100c5c9b799f2fb127775b8b2382ecc (diff)
downloadeurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.tar.gz
eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.tar.xz
eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.zip
Moved all malloc() operations over to a calloc wrapper, malloc_nullsafe()
This also improves debugging as well, if debug logging is enabled and log level is >= 40.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/eurephia.c11
-rw-r--r--plugin/eurephiadb_session.c29
-rw-r--r--plugin/firewall/eurephiafw.c8
3 files changed, 18 insertions, 30 deletions
diff --git a/plugin/eurephia.c b/plugin/eurephia.c
index 518ba34..82a3097 100644
--- a/plugin/eurephia.c
+++ b/plugin/eurephia.c
@@ -34,9 +34,11 @@
#include <stdarg.h>
#include <string.h>
#include <getopt.h>
+#include <assert.h>
#define EUREPHIA_FWINTF /**< Include the proper eurephiaFWINTF declaration in eurephiaCTX */
#include <eurephiafw_struct.h>
+#include <eurephia_nullsafe.h>
#include <eurephia_context.h>
#include <eurephiadb.h>
#include <eurephiadb_driver.h>
@@ -176,8 +178,8 @@ eurephiaCTX *eurephiaInit(const char **argv)
// End of argument parsing
// Prepare a context area for eurephia-auth
- ctx = (eurephiaCTX *) malloc(sizeof(eurephiaCTX)+2);
- memset(ctx, 0, sizeof(eurephiaCTX)+2);
+ ctx = (eurephiaCTX *) malloc_nullsafe(NULL, sizeof(eurephiaCTX)+2);
+ assert( ctx != NULL );
ctx->context_type = ECTX_PLUGIN_AUTH;
// Open a log file
@@ -224,8 +226,9 @@ eurephiaCTX *eurephiaInit(const char **argv)
}
// Get data for server_salt - which will be used for the password cache
- ctx->server_salt = (char *) malloc(SIZE_PWDCACHE_SALT+2);
- memset(ctx->server_salt, 0, SIZE_PWDCACHE_SALT+2);
+ ctx->server_salt = (char *) malloc_nullsafe(ctx, SIZE_PWDCACHE_SALT+2);
+ assert( ctx->server_salt != NULL );
+
if( !eurephia_randstring(ctx, ctx->server_salt, SIZE_PWDCACHE_SALT) ) {
eurephia_log(ctx, LOG_PANIC, 0 , "Could not get enough random data for password cache.");
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
diff --git a/plugin/firewall/eurephiafw.c b/plugin/firewall/eurephiafw.c
index 0ee83de..10d48a7 100644
--- a/plugin/firewall/eurephiafw.c
+++ b/plugin/firewall/eurephiafw.c
@@ -38,6 +38,7 @@
#include <sys/mman.h>
#include <sys/wait.h>
#include <time.h>
+#include <assert.h>
#define EUREPHIA_FWINTF
#include <eurephiafw_struct.h>
@@ -139,12 +140,11 @@ void eFW_StartFirewall(eurephiaCTX *ctx) {
char buf[1026], *fwdest = NULL;
unsigned int prio;
- ctx->fwcfg = (eurephiaFWINTF *) malloc(sizeof(eurephiaFWINTF)+2);
- memset(ctx->fwcfg, 0, sizeof(eurephiaFWINTF)+2);
+ ctx->fwcfg = (eurephiaFWINTF *) malloc_nullsafe(ctx, sizeof(eurephiaFWINTF)+2);
// Create a fake eurephia context, just for logging
- shadowctx = (eurephiaCTX *) malloc(sizeof(eurephiaCTX)+2);
- memset(shadowctx, 0, sizeof(eurephiaCTX)+2);
+ shadowctx = (eurephiaCTX *) malloc_nullsafe(ctx, sizeof(eurephiaCTX)+2);
+ assert( shadowctx != NULL );
shadowctx->context_type = ECTX_NO_PRIVILEGES;
shadowctx->loglevel = ctx->loglevel;
shadowctx->log = ctx->log;