diff options
author | startx2017 <vradu.startx@yandex.com> | 2018-03-12 08:41:01 -0400 |
---|---|---|
committer | startx2017 <vradu.startx@yandex.com> | 2018-03-12 08:41:01 -0400 |
commit | 14b5746d8fba392c02733ce4c90befc32a93fb15 (patch) | |
tree | 2ac6a7de4adaafc730511a70f11b88aca1f47244 /src/lib | |
parent | fix bash on CentOS 7 (diff) | |
download | firejail-14b5746d8fba392c02733ce4c90befc32a93fb15.tar.gz firejail-14b5746d8fba392c02733ce4c90befc32a93fb15.tar.zst firejail-14b5746d8fba392c02733ce4c90befc32a93fb15.zip |
private-lib bug: 32 bit libraries being copied instead of 64 bit versions; splitting common code for firejail and fldd in a common static library
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.in | 2 | ||||
-rw-r--r-- | src/lib/ldd_utils.c | 62 |
2 files changed, 63 insertions, 1 deletions
diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index 63b0ad56d..a49e56ad2 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in | |||
@@ -10,7 +10,7 @@ H_FILE_LIST = $(sort $(wildcard *.[h])) | |||
10 | C_FILE_LIST = $(sort $(wildcard *.c)) | 10 | C_FILE_LIST = $(sort $(wildcard *.c)) |
11 | OBJS = $(C_FILE_LIST:.c=.o) | 11 | OBJS = $(C_FILE_LIST:.c=.o) |
12 | BINOBJS = $(foreach file, $(OBJS), $file) | 12 | BINOBJS = $(foreach file, $(OBJS), $file) |
13 | CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_GCOV) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security | 13 | CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -DLIBDIR='"$(libdir)"' $(HAVE_GCOV) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security |
14 | LDFLAGS:=-pic -Wl,-z,relro -Wl,-z,now | 14 | LDFLAGS:=-pic -Wl,-z,relro -Wl,-z,now |
15 | 15 | ||
16 | all: $(OBJS) | 16 | all: $(OBJS) |
diff --git a/src/lib/ldd_utils.c b/src/lib/ldd_utils.c new file mode 100644 index 000000000..556fb02eb --- /dev/null +++ b/src/lib/ldd_utils.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2018 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #include "../include/ldd_utils.h" | ||
22 | #include <sys/types.h> | ||
23 | #include <sys/stat.h> | ||
24 | #include <fcntl.h> | ||
25 | |||
26 | const char * const default_lib_paths[] = { | ||
27 | "/lib", | ||
28 | "/lib/x86_64-linux-gnu", | ||
29 | "/lib64", | ||
30 | "/usr/lib", | ||
31 | "/usr/lib/x86_64-linux-gnu", | ||
32 | LIBDIR, | ||
33 | "/usr/local/lib", | ||
34 | "/usr/lib/x86_64-linux-gnu/mesa", // libGL.so is sometimes a symlink into this directory | ||
35 | "/usr/lib/x86_64-linux-gnu/mesa-egl", // libGL.so is sometimes a symlink into this directory | ||
36 | // "/usr/lib/x86_64-linux-gnu/plasma-discover", | ||
37 | NULL | ||
38 | }; | ||
39 | |||
40 | // return 1 if this is a 64 bit program/library | ||
41 | int is_lib_64(const char *exe) { | ||
42 | int retval = 0; | ||
43 | int fd = open(exe, O_RDONLY); | ||
44 | if (fd < 0) | ||
45 | return 0; | ||
46 | |||
47 | unsigned char buf[EI_NIDENT]; | ||
48 | ssize_t len = 0; | ||
49 | while (len < EI_NIDENT) { | ||
50 | ssize_t sz = read(fd, buf, EI_NIDENT); | ||
51 | if (sz <= 0) | ||
52 | goto doexit; | ||
53 | len += sz; | ||
54 | } | ||
55 | |||
56 | if (buf[EI_CLASS] == ELFCLASS64) | ||
57 | retval = 1; | ||
58 | |||
59 | doexit: | ||
60 | close(fd); | ||
61 | return retval; | ||
62 | } | ||