[PATCH] D62973: [llvm-objcopy] Error when --preserve-dates used on standard streams

Alex Brachet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 12:33:20 PDT 2019


abrachet created this revision.
abrachet added reviewers: jhenderson, rupprecht.
Herald added subscribers: llvm-commits, MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a project: LLVM.

Ensure --preserve-dates is only ever used when both input and output files are regular files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62973

Files:
  llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp


Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ErrorOr.h"
@@ -206,10 +207,13 @@
 /// format-agnostic modifications, i.e. preserving dates.
 static Error executeObjcopy(const CopyConfig &Config) {
   sys::fs::file_status Stat;
-  if (Config.PreserveDates)
+  if (Config.PreserveDates) {
+    if (Config.InputFilename == "-" || Config.OutputFilename == "-")
+      return createStringError(errc::invalid_argument,
+                               "--preserve-dates requires a file");
     if (auto EC = sys::fs::status(Config.InputFilename, Stat))
       return createFileError(Config.InputFilename, EC);
-
+  }
   if (Config.InputFormat == "binary") {
     auto BufOrErr = MemoryBuffer::getFile(Config.InputFilename);
     if (!BufOrErr)
Index: llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
@@ -0,0 +1,5 @@
+# RUN: llvm-objcopy --preserve-dates - %t < %p/Inputs/alloc-symtab.o
+# CHECK: error: --preserve-dates requires a file
+
+# RUN: llvm-objcopy --preserve-dates %p/Inputs/alloc-symtab.o - 
+# CHECK: error: --preserve-dates requires a file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62973.203418.patch
Type: text/x-patch
Size: 1614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190606/3d30dca1/attachment-0001.bin>


More information about the llvm-commits mailing list