Make clone more aggressive about copying strings to the new entry.

The original might have pointers to user-specified strings;
copying the string (instead of just the pointer) protects against
the client re-using their own buffers.

I'm trying hard to avoid dumping all of the 'set' string functions
in favor of slower, but more predictable 'copy' semantics.
This commit is contained in:
kientzle 2004-04-23 17:15:48 +00:00
parent 1291cc3eae
commit fd3f8b3142

View File

@ -150,13 +150,13 @@ void
aes_copy(struct aes *dest, struct aes *src)
{
*dest = *src;
if (src->aes_mbs_alloc != NULL) {
dest->aes_mbs_alloc = strdup(src->aes_mbs_alloc);
if (src->aes_mbs != NULL) {
dest->aes_mbs_alloc = strdup(src->aes_mbs);
dest->aes_mbs = dest->aes_mbs_alloc;
}
if (src->aes_wcs_alloc != NULL) {
dest->aes_wcs_alloc = malloc((wcslen(src->aes_wcs_alloc) + 1)
if (src->aes_wcs != NULL) {
dest->aes_wcs_alloc = malloc((wcslen(src->aes_wcs) + 1)
* sizeof(wchar_t));
dest->aes_wcs = dest->aes_wcs_alloc;
wcscpy(dest->aes_wcs_alloc, src->aes_wcs);
@ -292,12 +292,12 @@ archive_entry_clone(struct archive_entry *entry)
memset(entry2, 0, sizeof(*entry2));
entry2->ae_stat = entry->ae_stat;
aes_copy(&entry2->ae_fflags ,&entry->ae_fflags);
aes_copy(&entry2->ae_gname ,&entry->ae_gname);
aes_copy(&entry2->ae_hardlink ,&entry->ae_hardlink);
aes_copy(&entry2->ae_fflags, &entry->ae_fflags);
aes_copy(&entry2->ae_gname, &entry->ae_gname);
aes_copy(&entry2->ae_hardlink, &entry->ae_hardlink);
aes_copy(&entry2->ae_pathname, &entry->ae_pathname);
aes_copy(&entry2->ae_symlink ,&entry->ae_symlink);
aes_copy(&entry2->ae_uname ,&entry->ae_uname);
aes_copy(&entry2->ae_symlink, &entry->ae_symlink);
aes_copy(&entry2->ae_uname, &entry->ae_uname);
return (entry2);
}