]> Dogcows Code - chaz/tar/commitdiff
(delay_set_stat): Fix off-by-one error in file
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 Aug 2001 21:37:27 +0000 (21:37 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 Aug 2001 21:37:27 +0000 (21:37 +0000)
name size allocation that caused core dumps.
From Jan.Djarv@mbox200.swipnet.se.
(extract_archive): Use strcpy, not memcpy,
for consistency with other code that does similar things.

src/extract.c

index d1401b32dcee13b0bf458550349a213d0f040908..ee3720df3182a8776066f77de3b909a8a2e93d98 100644 (file)
@@ -281,7 +281,8 @@ delay_set_stat (char const *file_name, struct stat const *stat_info,
 {
   size_t file_name_len = strlen (file_name);
   struct delayed_set_stat *data =
-    xmalloc (offsetof (struct delayed_set_stat, file_name) + file_name_len);
+    xmalloc (offsetof (struct delayed_set_stat, file_name)
+            + file_name_len + 1);
   data->file_name_len = file_name_len;
   strcpy (data->file_name, file_name);
   data->invert_permissions = invert_permissions;
@@ -899,11 +900,9 @@ extract_archive (void)
            close_error (CURRENT_FILE_NAME);
          else
            {
-             size_t filelen = strlen (CURRENT_FILE_NAME);
-             size_t linklen = strlen (current_link_name);
              struct delayed_symlink *p =
                xmalloc (offsetof (struct delayed_symlink, target)
-                        + linklen + 1);
+                        + strlen (current_link_name) + 1);
              p->next = delayed_symlink_head;
              delayed_symlink_head = p;
              p->dev = st.st_dev;
@@ -912,10 +911,10 @@ extract_archive (void)
              p->uid = current_stat.st_uid;
              p->gid = current_stat.st_gid;
              p->sources = xmalloc (offsetof (struct string_list, string)
-                                   + filelen + 1);
+                                   + strlen (CURRENT_FILE_NAME) + 1);
              p->sources->next = 0;
-             memcpy (p->sources->string, CURRENT_FILE_NAME, filelen + 1);
-             memcpy (p->target, current_link_name, linklen + 1);
+             strcpy (p->sources->string, CURRENT_FILE_NAME);
+             strcpy (p->target, current_link_name);
              status = 0;
            }
        }
This page took 0.028515 seconds and 4 git commands to generate.