]> Dogcows Code - chaz/tar/commitdiff
tar: port -d to longer symlinks
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Jul 2015 16:46:17 +0000 (09:46 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Jul 2015 16:53:56 +0000 (09:53 -0700)
* src/compare.c (diff_symlink):
Don't use alloca on symlink length; it might be too big for the stack.
Don't assume that readlinkat's return value fits in 'int'.
Prefer memcmp to strncmp where either will do.

src/compare.c

index d29cfdd4822f683dec5c7dfb8dc01544c62330ce..7ed455848791cd40433dd52aea4b17155e970b3b 100644 (file)
@@ -270,11 +270,12 @@ diff_link (void)
 static void
 diff_symlink (void)
 {
+  char buf[1024];
   size_t len = strlen (current_stat_info.link_name);
-  char *linkbuf = alloca (len + 1);
+  char *linkbuf = len < sizeof buf ? buf : xmalloc (len + 1);
 
-  int status = readlinkat (chdir_fd, current_stat_info.file_name,
-                          linkbuf, len + 1);
+  ssize_t status = readlinkat (chdir_fd, current_stat_info.file_name,
+                              linkbuf, len + 1);
 
   if (status < 0)
     {
@@ -285,8 +286,11 @@ diff_symlink (void)
       report_difference (&current_stat_info, NULL);
     }
   else if (status != len
-          || strncmp (current_stat_info.link_name, linkbuf, len) != 0)
+          || memcmp (current_stat_info.link_name, linkbuf, len) != 0)
     report_difference (&current_stat_info, _("Symlink differs"));
+
+  if (linkbuf != buf)
+    free (linkbuf);
 }
 #endif
 
This page took 0.029644 seconds and 4 git commands to generate.