From 14b5746d8fba392c02733ce4c90befc32a93fb15 Mon Sep 17 00:00:00 2001 From: startx2017 Date: Mon, 12 Mar 2018 08:41:01 -0400 Subject: 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 --- src/lib/Makefile.in | 2 +- src/lib/ldd_utils.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/lib/ldd_utils.c (limited to 'src/lib') 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])) C_FILE_LIST = $(sort $(wildcard *.c)) OBJS = $(C_FILE_LIST:.c=.o) BINOBJS = $(foreach file, $(OBJS), $file) -CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_GCOV) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security +CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -DLIBDIR='"$(libdir)"' $(HAVE_GCOV) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security LDFLAGS:=-pic -Wl,-z,relro -Wl,-z,now 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 @@ +/* + * Copyright (C) 2014-2018 Firejail Authors + * + * This file is part of firejail project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "../include/ldd_utils.h" +#include +#include +#include + +const char * const default_lib_paths[] = { + "/lib", + "/lib/x86_64-linux-gnu", + "/lib64", + "/usr/lib", + "/usr/lib/x86_64-linux-gnu", + LIBDIR, + "/usr/local/lib", + "/usr/lib/x86_64-linux-gnu/mesa", // libGL.so is sometimes a symlink into this directory + "/usr/lib/x86_64-linux-gnu/mesa-egl", // libGL.so is sometimes a symlink into this directory +// "/usr/lib/x86_64-linux-gnu/plasma-discover", + NULL +}; + +// return 1 if this is a 64 bit program/library +int is_lib_64(const char *exe) { + int retval = 0; + int fd = open(exe, O_RDONLY); + if (fd < 0) + return 0; + + unsigned char buf[EI_NIDENT]; + ssize_t len = 0; + while (len < EI_NIDENT) { + ssize_t sz = read(fd, buf, EI_NIDENT); + if (sz <= 0) + goto doexit; + len += sz; + } + + if (buf[EI_CLASS] == ELFCLASS64) + retval = 1; + +doexit: + close(fd); + return retval; +} -- cgit v1.2.3-54-g00ecf