Add dependencies to configure rule
[external/binutils.git] / binutils / bucomm.c
index 8272d6a..da7cfad 100644 (file)
@@ -1,7 +1,5 @@
 /* bucomm.c -- Bin Utils COMmon code.
-   Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002,
-   2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014
-   Free Software Foundation, Inc.
+   Copyright (C) 1991-2016 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -88,7 +86,7 @@ bfd_nonfatal_message (const char *filename,
   section_name = NULL;
   va_start (args, format);
   fprintf (stderr, "%s", program_name);
-  
+
   if (abfd)
     {
       if (!filename)
@@ -431,8 +429,12 @@ print_arelt_descr (FILE *file, bfd *abfd, bfd_boolean verbose)
          const char *ctime_result = (const char *) ctime (&when);
          bfd_size_type size;
 
-         /* POSIX format:  skip weekday and seconds from ctime output.  */
-         sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20);
+         /* PR binutils/17605: Check for corrupt time values.  */
+         if (ctime_result == NULL)
+           sprintf (timebuf, _("<time data corrupt>"));
+         else
+           /* POSIX format:  skip weekday and seconds from ctime output.  */
+           sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20);
 
          mode_string (buf.st_mode, modebuf);
          modebuf[10] = '\0';
@@ -572,7 +574,7 @@ off_t
 get_file_size (const char * file_name)
 {
   struct stat statbuf;
-  
+
   if (stat (file_name, &statbuf) < 0)
     {
       if (errno == ENOENT)
@@ -580,7 +582,7 @@ get_file_size (const char * file_name)
       else
        non_fatal (_("Warning: could not locate '%s'.  reason: %s"),
                   file_name, strerror (errno));
-    }  
+    }
   else if (! S_ISREG (statbuf.st_mode))
     non_fatal (_("Warning: '%s' is not an ordinary file"), file_name);
   else if (statbuf.st_size < 0)
@@ -602,7 +604,7 @@ bfd_get_archive_filename (const bfd *abfd)
   size_t needed;
 
   assert (abfd != NULL);
-  
+
   if (!abfd->my_archive)
     return bfd_get_filename (abfd);
 
@@ -626,3 +628,29 @@ bfd_get_archive_filename (const bfd *abfd)
           bfd_get_filename (abfd));
   return buf;
 }
+
+/* Returns TRUE iff PATHNAME, a filename of an archive member,
+   is valid for writing.  For security reasons absolute paths
+   and paths containing /../ are not allowed.  See PR 17533.  */
+
+bfd_boolean
+is_valid_archive_path (char const * pathname)
+{
+  const char * n = pathname;
+
+  if (IS_ABSOLUTE_PATH (n))
+    return FALSE;
+
+  while (*n)
+    {
+      if (*n == '.' && *++n == '.' && ( ! *++n || IS_DIR_SEPARATOR (*n)))
+       return FALSE;
+
+      while (*n && ! IS_DIR_SEPARATOR (*n))
+       n++;
+      while (IS_DIR_SEPARATOR (*n))
+       n++;
+    }
+
+  return TRUE;
+}