Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 1 | From 7f1fd10cfebd5ea2f3e1938abe1bd1c4828164a7 Mon Sep 17 00:00:00 2001 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2 | From: Fabio Berton <fabio.berton@ossystems.com.br> |
| 3 | Date: Fri, 9 Sep 2016 16:00:42 -0300 |
| 4 | Subject: [PATCH] handle read-only files |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 5 | |
| 6 | Patch from: |
| 7 | https://github.com/darealshinji/patchelf/commit/40e66392bc4b96e9b4eda496827d26348a503509 |
| 8 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 9 | Upstream-Status: Denied [https://github.com/NixOS/patchelf/pull/89] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10 | |
| 11 | Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br> |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 12 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 13 | --- |
| 14 | src/patchelf.cc | 16 +++++++++++++++- |
| 15 | 1 file changed, 15 insertions(+), 1 deletion(-) |
| 16 | |
| 17 | diff --git a/src/patchelf.cc b/src/patchelf.cc |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 18 | index 0b4965adff83..b5db2aef0e8a 100644 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | --- a/src/patchelf.cc |
| 20 | +++ b/src/patchelf.cc |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 21 | @@ -497,7 +497,17 @@ void ElfFile<ElfFileParamNames>::sortShdrs() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 22 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 23 | static void writeFile(std::string fileName, FileContents contents) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 24 | { |
| 25 | - int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY); |
| 26 | + struct stat st; |
| 27 | + int fd; |
| 28 | + |
| 29 | + if (stat(fileName.c_str(), &st) != 0) |
| 30 | + error("stat"); |
| 31 | + |
| 32 | + if (chmod(fileName.c_str(), 0600) != 0) |
| 33 | + error("chmod"); |
| 34 | + |
| 35 | + fd = open(fileName.c_str(), O_TRUNC | O_WRONLY); |
| 36 | + |
| 37 | if (fd == -1) |
| 38 | error("open"); |
| 39 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 40 | @@ -511,6 +521,10 @@ static void writeFile(std::string fileName, FileContents contents) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | |
| 42 | if (close(fd) != 0) |
| 43 | error("close"); |
| 44 | + |
| 45 | + if (chmod(fileName.c_str(), st.st_mode) != 0) |
| 46 | + error("chmod"); |
| 47 | + |
| 48 | } |
| 49 | |
| 50 | |