]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Added a null-safe strdup variant
authorMartin Willi <martin@revosec.ch>
Wed, 15 Dec 2010 11:15:12 +0000 (12:15 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 5 Jan 2011 15:46:02 +0000 (16:46 +0100)
src/libcharon/config/child_cfg.c
src/libcharon/config/peer_cfg.c
src/libcharon/plugins/android/android_creds.c
src/libcharon/plugins/nm/nm_creds.c
src/libfast/request.c
src/libstrongswan/settings.c
src/libstrongswan/utils.h

index 8ca3224843ac8e5d351f817939911539301a9b1d..74949be3ca604014ec243efe8879056e17512b13 100644 (file)
@@ -536,7 +536,7 @@ child_cfg_t *child_cfg_create(char *name, lifetime_cfg_t *lifetime,
                        .destroy = _destroy,
                },
                .name = strdup(name),
-               .updown = updown ? strdup(updown) : NULL,
+               .updown = strdupnull(updown),
                .hostaccess = hostaccess,
                .mode = mode,
                .start_action = start_action,
index 9df14c9ae42198d5b89b8afcde8ba52600dbf494..6f0c872794c4de970c4cbce17d8f4cb9d19720d7 100644 (file)
@@ -682,7 +682,7 @@ peer_cfg_t *peer_cfg_create(char *name, u_int ike_version, ike_cfg_t *ike_cfg,
        this->use_mobike = mobike;
        this->dpd = dpd;
        this->virtual_ip = virtual_ip;
-       this->pool = pool ? strdup(pool) : NULL;
+       this->pool = strdupnull(pool);
        this->local_auth = linked_list_create();
        this->remote_auth = linked_list_create();
        this->refcount = 1;
index aa7fc6f922f8ba557d675762608b4b786c8a064b..601c91e7bf3cbe19e923aadeff11aa5817325237 100644 (file)
@@ -235,7 +235,7 @@ METHOD(android_creds_t, set_username_password, void,
        DESTROY_IF(this->user);
        this->user = id->clone(id);
        free(this->pass);
-       this->pass = password ? strdup(password) : NULL;
+       this->pass = strdupnull(password);
        this->lock->unlock(this->lock);
 }
 
index 638787019339b75784edf78489931e72901ca935..ea98c056d60f24f5fcaaa1a877e8d3169fd5a045 100644 (file)
@@ -400,7 +400,7 @@ static void set_username_password(private_nm_creds_t *this, identification_t *id
        DESTROY_IF(this->user);
        this->user = id->clone(id);
        free(this->pass);
-       this->pass = password ? strdup(password) : NULL;
+       this->pass = strdupnull(password);
        this->lock->unlock(this->lock);
 }
 
@@ -411,7 +411,7 @@ static void set_key_password(private_nm_creds_t *this, char *password)
 {
        this->lock->write_lock(this->lock);
        free(this->keypass);
-       this->keypass = password ? strdup(password) : NULL;
+       this->keypass = strdupnull(password);
        this->lock->unlock(this->lock);
 }
 
@@ -423,7 +423,7 @@ static void set_pin(private_nm_creds_t *this, chunk_t keyid, char *pin)
        this->lock->write_lock(this->lock);
        free(this->keypass);
        free(this->keyid.ptr);
-       this->keypass = pin ? strdup(pin) : NULL;
+       this->keypass = strdupnull(pin);
        this->keyid = chunk_clone(keyid);
        this->lock->unlock(this->lock);
 }
index 89e91b3773b0d277c9334e4c9ffda2c219d4237f..a3db70e823465b908bc997c21867c1d72322af90 100644 (file)
@@ -120,7 +120,7 @@ static char *getenv_cb(void *null, const char *key)
        private_request_t *this = (private_request_t*)thread_this->get(thread_this);
 
        value = FCGX_GetParam(key, this->req.envp);
-       return value ? strdup(value) : NULL;
+       return strdupnull(value);
 }
 
 /**
index 47ed60edca32d2a43c63ff2475a8231f44658615..bd279f51df46472685be0a8deaa508136a7ef000 100644 (file)
@@ -127,7 +127,7 @@ static section_t *section_create(char *name)
 {
        section_t *this;
        INIT(this,
-               .name = name ? strdup(name) : NULL,
+               .name = strdupnull(name),
                .sections = linked_list_create(),
                .kv = linked_list_create(),
        );
index 8ab7322057f2ece37186b8d9fff1be7d38d8a125..ed61895ee973f4a9f86e938a21104a1fd26957c1 100644 (file)
  */
 #define strncaseeq(x,y,len) (strncasecmp(x, y, len) == 0)
 
+/**
+ * NULL-safe strdup variant
+ */
+#define strdupnull(x) ({ char *_x = x; _x ? strdup(_x) : NULL; })
+
 /**
  * Macro compares two binary blobs for equality
  */