gas: run the hwcaps-bump tests with 64-bit sparc objects only.
[deliverable/binutils-gdb.git] / binutils / ar.c
index 987b46cb0e7e0c8447fa3a6969cd4893d91577fb..ba0d5810fa1889feebc04b17c9a6ee4936719147 100644 (file)
@@ -1,5 +1,5 @@
 /* ar.c - Archive modify and extract.
-   Copyright 1991-2013 Free Software Foundation, Inc.
+   Copyright (C) 1991-2016 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
 #include "progress.h"
 #include "getopt.h"
 #include "aout/ar.h"
-#include "libbfd.h"
 #include "bucomm.h"
 #include "arsup.h"
 #include "filenames.h"
 #include "binemul.h"
+#include "plugin-api.h"
 #include "plugin.h"
 
 #ifdef __GO32___
@@ -138,7 +138,11 @@ static int show_version = 0;
 
 static int show_help = 0;
 
+#if BFD_SUPPORTS_PLUGINS
+static const char *plugin_target = "plugin";
+#else
 static const char *plugin_target = NULL;
+#endif
 
 static const char *target = NULL;
 
@@ -571,7 +575,6 @@ decode_options (int argc, char **argv)
           break;
        case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
-         plugin_target = "plugin";
          bfd_plugin_set_plugin (optarg);
 #else
          fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
@@ -632,7 +635,6 @@ ranlib_main (int argc, char **argv)
          /* PR binutils/13493: Support plugins.  */
        case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
-         plugin_target = "plugin";
          bfd_plugin_set_plugin (optarg);
 #else
          fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
@@ -689,6 +691,7 @@ main (int argc, char **argv)
 
   program_name = argv[0];
   xmalloc_set_program_name (program_name);
+  bfd_set_error_program_name (program_name);
 #if BFD_SUPPORTS_PLUGINS
   bfd_plugin_set_program_name (program_name);
 #endif
@@ -737,6 +740,7 @@ main (int argc, char **argv)
 
   if (mri_mode)
     {
+      default_deterministic ();
       mri_emul ();
     }
   else
@@ -951,7 +955,7 @@ open_inarch (const char *archive_filename, const char *file)
                 bfd_get_filename (arch));
          goto bloser;
        }
-    }  
+    }
 
   last_one = &(arch->archive_next);
   /* Read all the contents right away, regardless.  */
@@ -999,7 +1003,7 @@ print_contents (bfd *abfd)
       if (nread != tocopy)
        /* xgettext:c-format */
        fatal (_("%s is not a valid archive"),
-              bfd_get_filename (bfd_my_archive (abfd)));
+              bfd_get_filename (abfd->my_archive));
 
       /* fwrite in mingw32 may return int instead of bfd_size_type. Cast the
         return value to bfd_size_type to avoid comparison between signed and
@@ -1031,6 +1035,16 @@ extract_file (bfd *abfd)
   bfd_size_type size;
   struct stat buf;
 
+  /* PR binutils/17533: Do not allow directory traversal
+     outside of the current directory tree.  */
+  if (! is_valid_archive_path (bfd_get_filename (abfd)))
+    {
+      non_fatal (_("illegal pathname found in archive member: %s"),
+                bfd_get_filename (abfd));
+      free (cbuf);
+      return;
+    }
+
   if (bfd_stat_arch_elt (abfd, &buf) != 0)
     /* xgettext:c-format */
     fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
@@ -1067,7 +1081,7 @@ extract_file (bfd *abfd)
        if (nread != tocopy)
          /* xgettext:c-format */
          fatal (_("%s is not a valid archive"),
-                bfd_get_filename (bfd_my_archive (abfd)));
+                bfd_get_filename (abfd->my_archive));
 
        /* See comment above; this saves disk arm motion */
        if (ostream == NULL)
This page took 0.026407 seconds and 4 git commands to generate.