]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - elf/sln.c
Fix bad pointer / leak in regex code
[thirdparty/glibc.git] / elf / sln.c
index 1bad21f22629b1c61e9c4b5c10b62cb4a82caf10..57d29e94e2d88cecd0e4ab91c58aff50e67eaafe 100644 (file)
--- a/elf/sln.c
+++ b/elf/sln.c
@@ -1,5 +1,5 @@
 /* `sln' program to create symbolic links between files.
-   Copyright (C) 1998, 1999, 2001, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1998-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
 #include <error.h>
 #include <errno.h>
 #include <libintl.h>
 
 #define PACKAGE _libc_intl_domainname
 
-#if !defined S_ISDIR && defined S_IFDIR
-#define        S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
-
 static int makesymlink (const char *src, const char *dest);
 static int makesymlinks (const char *file);
 static void usage (void);
@@ -87,12 +79,8 @@ usage (void)
 }
 
 static int
-makesymlinks (file)
-     const char *file;
+makesymlinks (const char *file)
 {
-#ifndef PATH_MAX
-#define PATH_MAX 4095
-#endif
   char *buffer = NULL;
   size_t bufferlen = 0;
   int ret;
@@ -163,26 +151,24 @@ makesymlinks (file)
 }
 
 static int
-makesymlink (src, dest)
-     const char *src;
-     const char *dest;
+makesymlink (const char *src, const char *dest)
 {
-  struct stat stats;
+  struct stat64 stats;
   const char *error;
 
   /* Destination must not be a directory. */
-  if (lstat (dest, &stats) == 0)
+  if (lstat64 (dest, &stats) == 0)
     {
       if (S_ISDIR (stats.st_mode))
        {
          fprintf (stderr, _("%s: destination must not be a directory\n"),
-                  dest);
+                  dest);
          return 1;
        }
       else if (unlink (dest) && errno != ENOENT)
        {
          fprintf (stderr, _("%s: failed to remove the old destination\n"),
-                  dest);
+                  dest);
          return 1;
        }
     }
@@ -193,11 +179,7 @@ makesymlink (src, dest)
       return -1;
     }
 
-#ifdef S_ISLNK
   if (symlink (src, dest) == 0)
-#else
-  if (link (src, dest) == 0)
-#endif
     {
       /* Destination must exist by now. */
       if (access (dest, F_OK))
@@ -205,7 +187,7 @@ makesymlink (src, dest)
          error = strerror (errno);
          unlink (dest);
          fprintf (stderr, _("Invalid link from \"%s\" to \"%s\": %s\n"),
-                  src, dest, error);
+                  src, dest, error);
          return 1;
        }
       return 0;
@@ -214,7 +196,7 @@ makesymlink (src, dest)
     {
       error = strerror (errno);
       fprintf (stderr, _("Invalid link from \"%s\" to \"%s\": %s\n"),
-              src, dest, error);
+              src, dest, error);
       return 1;
     }
 }