diff options
author | smitsohu <smitsohu@gmail.com> | 2021-03-13 21:20:38 +0100 |
---|---|---|
committer | smitsohu <smitsohu@gmail.com> | 2021-03-14 04:38:58 +0100 |
commit | ae1d534074286bb6c206a13b7b07503ee458396a (patch) | |
tree | 5f6dc60cd021e1f1876fc400710984633215feb0 /src | |
parent | make appimage mounts private to sandbox (diff) | |
download | firejail-ae1d534074286bb6c206a13b7b07503ee458396a.tar.gz firejail-ae1d534074286bb6c206a13b7b07503ee458396a.tar.zst firejail-ae1d534074286bb6c206a13b7b07503ee458396a.zip |
appimage: calculate elf offset from file descriptor
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/appimage.c | 2 | ||||
-rw-r--r-- | src/firejail/appimage_size.c | 22 | ||||
-rw-r--r-- | src/firejail/firejail.h | 2 |
3 files changed, 10 insertions, 16 deletions
diff --git a/src/firejail/appimage.c b/src/firejail/appimage.c index cc66608d3..59758bf2d 100644 --- a/src/firejail/appimage.c +++ b/src/firejail/appimage.c | |||
@@ -61,7 +61,7 @@ void appimage_set(const char *appimage) { | |||
61 | 61 | ||
62 | // get appimage type and ELF size | 62 | // get appimage type and ELF size |
63 | // a value of 0 means we are dealing with a type1 appimage | 63 | // a value of 0 means we are dealing with a type1 appimage |
64 | size = appimage2_size(appimage); | 64 | size = appimage2_size(ffd); |
65 | if (arg_debug) | 65 | if (arg_debug) |
66 | printf("AppImage ELF size %lu\n", size); | 66 | printf("AppImage ELF size %lu\n", size); |
67 | 67 | ||
diff --git a/src/firejail/appimage_size.c b/src/firejail/appimage_size.c index 4640cb8a5..43ca501da 100644 --- a/src/firejail/appimage_size.c +++ b/src/firejail/appimage_size.c | |||
@@ -132,22 +132,20 @@ static long unsigned int read_elf64(int fd) { | |||
132 | 132 | ||
133 | // return 0 if error | 133 | // return 0 if error |
134 | // return 0 if this is not an appimgage2 file | 134 | // return 0 if this is not an appimgage2 file |
135 | long unsigned int appimage2_size(const char *fname) { | 135 | long unsigned int appimage2_size(int fd) { |
136 | ssize_t ret; | 136 | ssize_t ret; |
137 | int fd; | ||
138 | long unsigned int size = 0; | 137 | long unsigned int size = 0; |
139 | 138 | ||
140 | fd = open(fname, O_RDONLY); | ||
141 | if (fd < 0) | 139 | if (fd < 0) |
142 | return 0; | 140 | return 0; |
143 | 141 | ||
144 | ret = pread(fd, ehdr.e_ident, EI_NIDENT, 0); | 142 | ret = pread(fd, ehdr.e_ident, EI_NIDENT, 0); |
145 | if (ret != EI_NIDENT) | 143 | if (ret != EI_NIDENT) |
146 | goto getout; | 144 | return 0; |
147 | 145 | ||
148 | if ((ehdr.e_ident[EI_DATA] != ELFDATA2LSB) && | 146 | if ((ehdr.e_ident[EI_DATA] != ELFDATA2LSB) && |
149 | (ehdr.e_ident[EI_DATA] != ELFDATA2MSB)) | 147 | (ehdr.e_ident[EI_DATA] != ELFDATA2MSB)) |
150 | goto getout; | 148 | return 0; |
151 | 149 | ||
152 | if(ehdr.e_ident[EI_CLASS] == ELFCLASS32) { | 150 | if(ehdr.e_ident[EI_CLASS] == ELFCLASS32) { |
153 | size = read_elf32(fd); | 151 | size = read_elf32(fd); |
@@ -156,23 +154,19 @@ long unsigned int appimage2_size(const char *fname) { | |||
156 | size = read_elf64(fd); | 154 | size = read_elf64(fd); |
157 | } | 155 | } |
158 | else { | 156 | else { |
159 | goto getout; | 157 | return 0; |
160 | } | 158 | } |
161 | if (size == 0) | 159 | if (size == 0) |
162 | goto getout; | 160 | return 0; |
163 | 161 | ||
164 | 162 | ||
165 | // look for a LZMA header at this location | 163 | // look for a LZMA header at this location |
166 | unsigned char buf[4]; | 164 | unsigned char buf[4]; |
167 | ret = pread(fd, buf, 4, size); | 165 | ret = pread(fd, buf, 4, size); |
168 | if (ret != 4) { | 166 | if (ret != 4) |
169 | size = 0; | 167 | return 0; |
170 | goto getout; | ||
171 | } | ||
172 | if (memcmp(buf, "hsqs", 4) != 0) | 168 | if (memcmp(buf, "hsqs", 4) != 0) |
173 | size = 0; | 169 | return 0; |
174 | 170 | ||
175 | getout: | ||
176 | close(fd); | ||
177 | return size; | 171 | return size; |
178 | } | 172 | } |
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 3b9a00c3f..ca4c988fa 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -802,7 +802,7 @@ void appimage_mount(void); | |||
802 | void appimage_clear(void); | 802 | void appimage_clear(void); |
803 | 803 | ||
804 | // appimage_size.c | 804 | // appimage_size.c |
805 | long unsigned int appimage2_size(const char *fname); | 805 | long unsigned int appimage2_size(int fd); |
806 | 806 | ||
807 | // cmdline.c | 807 | // cmdline.c |
808 | void build_cmdline(char **command_line, char **window_title, int argc, char **argv, int index); | 808 | void build_cmdline(char **command_line, char **window_title, int argc, char **argv, int index); |