]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
Do not strdup() zero length strings in identification_create_from_string()
authorMartin Willi <martin@revosec.ch>
Tue, 31 Aug 2010 13:34:08 +0000 (15:34 +0200)
committerMartin Willi <martin@revosec.ch>
Tue, 31 Aug 2010 13:34:45 +0000 (15:34 +0200)
src/libstrongswan/utils/identification.c

index 3caeb8f0e71ac6aa33526b1a61a963a7e85ce650..0696c1030d9bb63fdba5a6dcac34665742a6ab0c 100644 (file)
@@ -930,7 +930,11 @@ identification_t *identification_create_from_string(char *string)
                                else
                                {       /* not IPv4, mostly FQDN */
                                        this = identification_create(ID_FQDN);
-                                       this->encoded = chunk_create(strdup(string), strlen(string));
+                                       this->encoded.len = strlen(string);
+                                       if (this->encoded.len)
+                                       {
+                                               this->encoded.ptr = strdup(string);
+                                       }
                                }
                                return &this->public;
                        }
@@ -947,7 +951,11 @@ identification_t *identification_create_from_string(char *string)
                                else
                                {       /* not IPv4/6 fallback to KEY_ID */
                                        this = identification_create(ID_KEY_ID);
-                                       this->encoded = chunk_create(strdup(string), strlen(string));
+                                       this->encoded.len = strlen(string);
+                                       if (this->encoded.len)
+                                       {
+                                               this->encoded.ptr = strdup(string);
+                                       }
                                }
                                return &this->public;
                        }
@@ -969,14 +977,22 @@ identification_t *identification_create_from_string(char *string)
                        {
                                this = identification_create(ID_FQDN);
                                string += 1;
-                               this->encoded = chunk_create(strdup(string), strlen(string));
+                               this->encoded.len = strlen(string);
+                               if (this->encoded.len)
+                               {
+                                       this->encoded.ptr = strdup(string);
+                               }
                                return &this->public;
                        }
                }
                else
                {
                        this = identification_create(ID_RFC822_ADDR);
-                       this->encoded = chunk_create(strdup(string), strlen(string));
+                       this->encoded.len = strlen(string);
+                       if (this->encoded.len)
+                       {
+                               this->encoded.ptr = strdup(string);
+                       }
                        return &this->public;
                }
        }