e63663
From be77b4ab7cb68fd2daf9de90bd75d844392788ac Mon Sep 17 00:00:00 2001
e63663
From: Kamil Dudka <kdudka@redhat.com>
e63663
Date: Thu, 25 Mar 2021 11:57:56 +0100
e63663
Subject: [PATCH 1/4] ln: fix memory leaks in do_link
e63663
e63663
* src/ln.c (do_link): Free memory allocated by convert_abs_rel
e63663
on all code paths (Bug#47373).
e63663
e63663
Upstream-commit: 6e98f67758260579d7d44ea5f2df4c82d28c9f58
e63663
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e63663
---
e63663
 src/ln.c | 19 +++++++++++++------
e63663
 1 file changed, 13 insertions(+), 6 deletions(-)
e63663
e63663
diff --git a/src/ln.c b/src/ln.c
e63663
index ffa278e..9b52602 100644
e63663
--- a/src/ln.c
e63663
+++ b/src/ln.c
e63663
@@ -229,14 +229,14 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
               if (errno != ENOENT)
e63663
                 {
e63663
                   error (0, errno, _("failed to access %s"), quoteaf (dest));
e63663
-                  return false;
e63663
+                  goto fail;
e63663
                 }
e63663
               force = false;
e63663
             }
e63663
           else if (S_ISDIR (dest_stats.st_mode))
e63663
             {
e63663
               error (0, 0, _("%s: cannot overwrite directory"), quotef (dest));
e63663
-              return false;
e63663
+              goto fail;
e63663
             }
e63663
           else if (seen_file (dest_set, dest, &dest_stats))
e63663
             {
e63663
@@ -245,7 +245,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
               error (0, 0,
e63663
                      _("will not overwrite just-created %s with %s"),
e63663
                      quoteaf_n (0, dest), quoteaf_n (1, source));
e63663
-              return false;
e63663
+              goto fail;
e63663
             }
e63663
           else
e63663
             {
e63663
@@ -274,7 +274,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
                     {
e63663
                       error (0, 0, _("%s and %s are the same file"),
e63663
                              quoteaf_n (0, source), quoteaf_n (1, dest));
e63663
-                      return false;
e63663
+                      goto fail;
e63663
                     }
e63663
                 }
e63663
 
e63663
@@ -285,7 +285,10 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
                       fprintf (stderr, _("%s: replace %s? "),
e63663
                                program_name, quoteaf (dest));
e63663
                       if (!yesno ())
e63663
-                        return true;
e63663
+                        {
e63663
+                          free(rel_source);
e63663
+                          return true;
e63663
+                        }
e63663
                     }
e63663
 
e63663
                   if (backup_type != no_backups)
e63663
@@ -304,7 +307,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
                            {
e63663
                               error (0, rename_errno, _("cannot backup %s"),
e63663
                                      quoteaf (dest));
e63663
-                              return false;
e63663
+                              goto fail;
e63663
                             }
e63663
                           force = false;
e63663
                         }
e63663
@@ -397,6 +400,10 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
   free (backup_base);
e63663
   free (rel_source);
e63663
   return link_errno <= 0;
e63663
+
e63663
+fail:
e63663
+  free (rel_source);
e63663
+  return false;
e63663
 }
e63663
 
e63663
 void
e63663
-- 
e63663
2.26.3
e63663
e63663
e63663
From c051578e69bd8acf8f8a469566ae34e855345532 Mon Sep 17 00:00:00 2001
e63663
From: Paul Eggert <eggert@cs.ucla.edu>
e63663
Date: Thu, 25 Mar 2021 09:15:50 -0700
e63663
Subject: [PATCH 2/4] maint: indenting
e63663
e63663
* src/ln.c: Fix indenting.
e63663
e63663
Upstream-commit: 8980b7c898046d899646da01c296fd15f0cced21
e63663
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e63663
---
e63663
 src/ln.c | 4 ++--
e63663
 1 file changed, 2 insertions(+), 2 deletions(-)
e63663
e63663
diff --git a/src/ln.c b/src/ln.c
e63663
index 9b52602..8881d6a 100644
e63663
--- a/src/ln.c
e63663
+++ b/src/ln.c
e63663
@@ -286,7 +286,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
                                program_name, quoteaf (dest));
e63663
                       if (!yesno ())
e63663
                         {
e63663
-                          free(rel_source);
e63663
+                          free (rel_source);
e63663
                           return true;
e63663
                         }
e63663
                     }
e63663
@@ -304,7 +304,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
e63663
                           free (backup_base);
e63663
                           backup_base = NULL;
e63663
                           if (rename_errno != ENOENT)
e63663
-                           {
e63663
+                            {
e63663
                               error (0, rename_errno, _("cannot backup %s"),
e63663
                                      quoteaf (dest));
e63663
                               goto fail;
e63663
-- 
e63663
2.26.3
e63663
e63663
e63663
From 0d6a4afe5bee0e397fb2fc3b205a29b32a69af9d Mon Sep 17 00:00:00 2001
e63663
From: Paul Eggert <eggert@cs.ucla.edu>
e63663
Date: Thu, 25 Mar 2021 09:16:36 -0700
e63663
Subject: [PATCH 3/4] hostname: use puts
e63663
e63663
* src/hostname.c (main): Prefer puts to printf "%s\n".
e63663
e63663
Upstream-commit: c7a588ac3632aae21642d4d568497177950d36bf
e63663
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e63663
---
e63663
 src/hostname.c | 2 +-
e63663
 1 file changed, 1 insertion(+), 1 deletion(-)
e63663
e63663
diff --git a/src/hostname.c b/src/hostname.c
e63663
index 0b5c0cf..62cc98c 100644
e63663
--- a/src/hostname.c
e63663
+++ b/src/hostname.c
e63663
@@ -103,7 +103,7 @@ main (int argc, char **argv)
e63663
       hostname = xgethostname ();
e63663
       if (hostname == NULL)
e63663
         die (EXIT_FAILURE, errno, _("cannot determine hostname"));
e63663
-      printf ("%s\n", hostname);
e63663
+      puts (hostname);
e63663
     }
e63663
 
e63663
   if (optind + 1 < argc)
e63663
-- 
e63663
2.26.3
e63663
e63663
e63663
From 19c98d2080251edbaad9fb271aa10ad34f953500 Mon Sep 17 00:00:00 2001
e63663
From: Paul Eggert <eggert@cs.ucla.edu>
e63663
Date: Thu, 25 Mar 2021 11:20:18 -0700
e63663
Subject: [PATCH 4/4] hostname: pacify valgrind
e63663
e63663
* src/hostname.c (main) [IF_LINT]: Free hostname (Bug#47384).
e63663
e63663
Upstream-commit: 4698e284f37844bc9b9f63f00eb556ccaaed5030
e63663
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e63663
---
e63663
 src/hostname.c | 1 +
e63663
 1 file changed, 1 insertion(+)
e63663
e63663
diff --git a/src/hostname.c b/src/hostname.c
e63663
index 62cc98c..7210248 100644
e63663
--- a/src/hostname.c
e63663
+++ b/src/hostname.c
e63663
@@ -104,6 +104,7 @@ main (int argc, char **argv)
e63663
       if (hostname == NULL)
e63663
         die (EXIT_FAILURE, errno, _("cannot determine hostname"));
e63663
       puts (hostname);
e63663
+      IF_LINT (free (hostname));
e63663
     }
e63663
 
e63663
   if (optind + 1 < argc)
e63663
-- 
e63663
2.26.3
e63663