blob: 9fafec4b592ab4414873a445d79555991647fe22 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001From 2a603acb65993698c21f1c6eb7664f93ad830d52 Mon Sep 17 00:00:00 2001
2From: Fabio Berton <fabio.berton@ossystems.com.br>
3Date: Fri, 9 Sep 2016 16:00:42 -0300
4Subject: [PATCH] handle read-only files
5Organization: O.S. Systems Software LTDA.
6
7Patch from:
8https://github.com/darealshinji/patchelf/commit/40e66392bc4b96e9b4eda496827d26348a503509
9
10Upstream-Status: Pending
11
12Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
13---
14 src/patchelf.cc | 16 +++++++++++++++-
15 1 file changed, 15 insertions(+), 1 deletion(-)
16
17diff --git a/src/patchelf.cc b/src/patchelf.cc
18index 136098f..aea360e 100644
19--- a/src/patchelf.cc
20+++ b/src/patchelf.cc
21@@ -388,7 +388,17 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
22
23 static void writeFile(string fileName)
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
40@@ -397,6 +407,10 @@ static void writeFile(string fileName)
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
51--
522.1.4
53