discovered the use of strndup()
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 15 Nov 2012 10:48:57 +0000 (11:48 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 15 Nov 2012 10:48:57 +0000 (11:48 +0100)
src/libimcv/ita/ita_attr_command.c
src/libimcv/ita/ita_attr_get_settings.c
src/libimcv/ita/ita_attr_settings.c
src/libimcv/plugins/imv_os/imv_os_database.c
src/libpts/tcg/tcg_pts_attr_req_file_meas.c
src/libpts/tcg/tcg_pts_attr_req_file_meta.c
src/libpts/tcg/tcg_pts_attr_unix_file_meta.c

index a1f1dd0..85beb49 100644 (file)
@@ -96,9 +96,7 @@ METHOD(pa_tnc_attr_t, build, void,
 METHOD(pa_tnc_attr_t, process, status_t,
        private_ita_attr_command_t *this, u_int32_t *offset)
 {
-       this->command = malloc(this->value.len + 1);
-       memcpy(this->command, this->value.ptr, this->value.len);
-       this->command[this->value.len] = '\0';
+       this->command = strndup(this->value.ptr, this->value.len);
 
        return SUCCESS;
 }
index c19a8bf..24fe6bf 100644 (file)
@@ -135,7 +135,6 @@ METHOD(pa_tnc_attr_t, process, status_t,
 {
        bio_reader_t *reader;
        u_int32_t count;
-       char *name_str;
        chunk_t name;
        status_t status = FAILED;
 
@@ -160,10 +159,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
                }
                *offset += 2 + name.len;
 
-               name_str = malloc(name.len + 1);
-               memcpy(name_str, name.ptr, name.len);
-               name_str[name.len] = '\0';
-               this->list->insert_last(this->list, name_str);
+               this->list->insert_last(this->list, strndup(name.ptr, name.len));
        }
        status = SUCCESS;
 
index 9f65768..e5d8274 100644 (file)
@@ -197,9 +197,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
                *offset += 2 + value.len;
 
                entry = malloc_thing(entry_t);
-               entry->name = malloc(name.len + 1);
-               memcpy(entry->name, name.ptr, name.len);
-               entry->name[name.len] = '\0';
+               entry->name = strndup(name.ptr, name.len);
                entry->value = chunk_clone(value);
                this->list->insert_last(this->list, entry);
        }
index 4ca8eb5..10c7b2a 100644 (file)
@@ -91,9 +91,7 @@ METHOD(imv_os_database_t, check_packages, status_t,
        while (package_enumerator->enumerate(package_enumerator, &name, &version))
        {
                /* Convert package name chunk to a string */
-               package = malloc(name.len + 1);
-               memcpy(package, name.ptr, name.len);
-               package[name.len] = '\0';
+               package = strndup(name.ptr, name.len);
                count++;
 
                /* Get primary key of package */
@@ -121,9 +119,7 @@ METHOD(imv_os_database_t, check_packages, status_t,
                e->destroy(e);
 
                /* Convert package version chunk to a string */
-               release = malloc(version.len + 1);
-               memcpy(release, version.ptr, version.len);
-               release[version.len] = '\0';
+               release = strndup(version.ptr, version.len);
 
                /* Enumerate over all acceptable versions */
                e = this->db->query(this->db,
index c28a40f..6eafc11 100644 (file)
@@ -169,10 +169,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
 
        this->directory_flag = (flags & DIRECTORY_CONTENTS_FLAG) !=
                                                        PTS_REQ_FILE_MEAS_NO_FLAGS;
-
-       this->pathname = malloc(pathname.len + 1);
-       memcpy(this->pathname, pathname.ptr, pathname.len);
-       this->pathname[pathname.len] = '\0';
+       this->pathname = strndup(pathname.ptr, pathname.len);
 
        reader->destroy(reader);
        return SUCCESS;
index 0ab8bef..88ee272 100644 (file)
@@ -162,10 +162,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
 
        this->directory_flag = (flags & DIRECTORY_CONTENTS_FLAG) !=
                                                        PTS_REQ_FILE_META_NO_FLAGS;
-
-       this->pathname = malloc(pathname.len + 1);
-       memcpy(this->pathname, pathname.ptr, pathname.len);
-       this->pathname[pathname.len] = '\0';
+       this->pathname = strndup(pathname.ptr, pathname.len);
 
        reader->destroy(reader);
        return SUCCESS;
index 9e15f3c..33e3a52 100644 (file)
@@ -252,9 +252,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
                entry->accessed = accessed;
                entry->owner = owner;
                entry->group = group;
-               entry->filename = malloc(filename.len + 1);
-               entry->filename[filename.len] = '\0';
-               memcpy(entry->filename, filename.ptr, filename.len);
+               entry->filename = strndup(filename.ptr, filename.len);
 
                this->metadata->add(this->metadata, entry);
        }