-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
private-lib bug: 32 bit libraries being copied instead of 64 bit vers…
…ions; splitting common code for firejail and fldd in a common static library
- Loading branch information
1 parent
2e17082
commit 14b5746
Showing
7 changed files
with
162 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#ifndef LDD_UTILS_H | ||
#define LDD_UTILS_H | ||
|
||
#include "../include/common.h" | ||
#include <elf.h> | ||
|
||
#ifdef __LP64__ | ||
#define Elf_Ehdr Elf64_Ehdr | ||
#define Elf_Phdr Elf64_Phdr | ||
#define Elf_Shdr Elf64_Shdr | ||
#define Elf_Dyn Elf64_Dyn | ||
#else | ||
#define Elf_Ehdr Elf32_Ehdr | ||
#define Elf_Phdr Elf32_Phdr | ||
#define Elf_Shdr Elf32_Shdr | ||
#define Elf_Dyn Elf32_Dyn | ||
#endif | ||
|
||
extern const char * const default_lib_paths[]; | ||
|
||
// return 1 if this is a 64 bit program/library | ||
int is_lib_64(const char *exe); | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
|
||
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; | ||
} |