]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
copy: sanity-check --suffix
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2017 00:11:24 +0000 (17:11 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2017 00:18:31 +0000 (17:18 -0700)
* src/cp.c, src/install.c, src/ln.c, src/mv.c (main):
Use set_simple_backup_suffix, to sanity-check the user-supplied
backup suffix.

NEWS
src/cp.c
src/install.c
src/ln.c
src/mv.c

diff --git a/NEWS b/NEWS
index 7c22ebbb426fda74a52bf7c14695eb02dd4e6f95..13bbc9606cd3ba2767e48245b427131330edc291 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   now makes a numbered backup file instead of losing the data.
   [the bug dates back to the initial implementation]
 
+  cp, install, ln, and mv now ignore nonsensical backup suffixes.
+  For example, --suffix='/' and --suffix='' are now no-ops.
+  [the bug dates back to the initial implementation]
+
   date and touch no longer overwrite the heap with large
   user specified TZ values (CVE-2017-7476).
   [bug introduced in coreutils-8.27]
index a6f0c64a8f18a84cf4606e8527c1baeb46bdb7aa..6949a677e3711e7b7251949b924fced3ba1e90a0 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -930,6 +930,7 @@ main (int argc, char **argv)
   int c;
   bool ok;
   bool make_backups = false;
+  char const *backup_suffix = NULL;
   char *version_control_string = NULL;
   struct cp_options x;
   bool copy_contents = false;
@@ -1126,7 +1127,7 @@ main (int argc, char **argv)
 
         case 'S':
           make_backups = true;
-          simple_backup_suffix = optarg;
+          backup_suffix = optarg;
           break;
 
         case_GETOPT_HELP_CHAR;
@@ -1161,6 +1162,7 @@ main (int argc, char **argv)
                    ? xget_version (_("backup type"),
                                    version_control_string)
                    : no_backups);
+  set_simple_backup_suffix (backup_suffix);
 
   if (x.dereference == DEREF_UNDEFINED)
     {
index 592c3452aec829f857a151a60e63f1209fb66720..5b6826112989cddf9d3b967bd0c27288458f40aa 100644 (file)
@@ -796,6 +796,7 @@ main (int argc, char **argv)
   int exit_status = EXIT_SUCCESS;
   const char *specified_mode = NULL;
   bool make_backups = false;
+  char const *backup_suffix = NULL;
   char *version_control_string = NULL;
   bool mkdir_and_install = false;
   struct cp_options x;
@@ -873,7 +874,7 @@ main (int argc, char **argv)
           break;
         case 'S':
           make_backups = true;
-          simple_backup_suffix = optarg;
+          backup_suffix = optarg;
           break;
         case 't':
           if (target_directory)
@@ -949,6 +950,7 @@ main (int argc, char **argv)
                    ? xget_version (_("backup type"),
                                    version_control_string)
                    : no_backups);
+  set_simple_backup_suffix (backup_suffix);
 
   if (x.preserve_security_context && (x.set_security_context || scontext))
     die (EXIT_FAILURE, 0,
index a70b7d50fe23cdd42cbfbf017da69161d8f5810a..e86f581b9e0dd52465adf18f7b980b3f66daf5e4 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -438,6 +438,7 @@ main (int argc, char **argv)
   int c;
   bool ok;
   bool make_backups = false;
+  char const *backup_suffix = NULL;
   char *version_control_string = NULL;
   char const *target_directory = NULL;
   bool no_target_directory = false;
@@ -515,7 +516,7 @@ main (int argc, char **argv)
           break;
         case 'S':
           make_backups = true;
-          simple_backup_suffix = optarg;
+          backup_suffix = optarg;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -565,6 +566,7 @@ main (int argc, char **argv)
   backup_type = (make_backups
                  ? xget_version (_("backup type"), version_control_string)
                  : no_backups);
+  set_simple_backup_suffix (backup_suffix);
 
   if (relative && !symbolic_link)
     {
index a6c6e3978f649a684e11710b2ed78c815d8c623e..fc1fca415d9f857102976eef1c064d42565e609d 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
@@ -336,6 +336,7 @@ main (int argc, char **argv)
   int c;
   bool ok;
   bool make_backups = false;
+  char const *backup_suffix = NULL;
   char *version_control_string = NULL;
   struct cp_options x;
   char *target_directory = NULL;
@@ -405,7 +406,7 @@ main (int argc, char **argv)
           break;
         case 'S':
           make_backups = true;
-          simple_backup_suffix = optarg;
+          backup_suffix = optarg;
           break;
         case 'Z':
           /* As a performance enhancement, don't even bother trying
@@ -469,6 +470,7 @@ main (int argc, char **argv)
                    ? xget_version (_("backup type"),
                                    version_control_string)
                    : no_backups);
+  set_simple_backup_suffix (backup_suffix);
 
   hash_init ();