ubsan: m10300: shift exponent -4
[deliverable/binutils-gdb.git] / binutils / ar.c
index 0af7954a47a2574f6a7cddac6454abe6f77b3bf4..1057db9980eddc4559ce5d8c253ddf483a29e1f5 100644 (file)
@@ -1,5 +1,5 @@
 /* ar.c - Archive modify and extract.
-   Copyright (C) 1991-2019 Free Software Foundation, Inc.
+   Copyright (C) 1991-2020 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -1070,6 +1070,18 @@ open_output_file (bfd * abfd)
 {
   output_filename = bfd_get_filename (abfd);
 
+  /* PR binutils/17533: Do not allow directory traversal
+     outside of the current directory tree - unless the
+     user has explicitly specified an output directory.  */
+  if (! is_valid_archive_path (output_filename))
+    {
+      char * base = (char *) lbasename (output_filename);
+
+      non_fatal (_("illegal output pathname for archive member: %s, using '%s' instead"),
+                output_filename, base);
+      output_filename = base;
+    }
+  
   if (output_dir)
     {
       size_t len = strlen (output_dir);
@@ -1083,18 +1095,10 @@ open_output_file (bfd * abfd)
            output_filename = concat (output_dir, "/", output_filename, NULL);
        }
     }
-    
-  /* PR binutils/17533: Do not allow directory traversal
-     outside of the current directory tree.  */
-  if (! is_valid_archive_path (output_filename))
-    {
-      char * base = (char *) lbasename (output_filename);
-
-      non_fatal (_("illegal output pathname for archive member: %s, using '%s' instead"),
-                output_filename, base);
-      output_filename = base;
-    }
 
+  if (verbose)
+    printf ("x - %s\n", output_filename);
+  
   FILE * ostream = fopen (output_filename, FOPEN_WB);
   if (ostream == NULL)
     {
@@ -1126,9 +1130,6 @@ extract_file (bfd *abfd)
     fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
   size = buf.st_size;
 
-  if (verbose)
-    printf ("x - %s\n", bfd_get_filename (abfd));
-
   bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
 
   output_file = NULL;
This page took 0.023648 seconds and 4 git commands to generate.