projects
/
project
/
procd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ujail: fixup code style: "func()" -> "func(void)"
[project/procd.git]
/
jail
/
elf.c
diff --git
a/jail/elf.c
b/jail/elf.c
index
cbb3051
..
c3a392c
100644
(file)
--- a/
jail/elf.c
+++ b/
jail/elf.c
@@
-16,23
+16,28
@@
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
-#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libgen.h>
#include <glob.h>
#include <elf.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libgen.h>
#include <glob.h>
#include <elf.h>
+#include <linux/limits.h>
#include <libubox/utils.h>
#include "elf.h"
#include <libubox/utils.h>
#include "elf.h"
+#include "log.h"
struct avl_tree libraries;
static LIST_HEAD(library_paths);
struct avl_tree libraries;
static LIST_HEAD(library_paths);
-void alloc_library_path(const char *path)
+
static
void alloc_library_path(const char *path)
{
{
+ struct stat s;
+ if (stat(path, &s))
+ return;
+
struct library_path *p;
char *_path;
struct library_path *p;
char *_path;
@@
-65,10
+70,10
@@
static void alloc_library(const char *path, const char *name)
DEBUG("adding library %s/%s\n", path, name);
}
DEBUG("adding library %s/%s\n", path, name);
}
-static int elf_open(char **dir, char *file)
+static int elf_open(char **dir, c
onst c
har *file)
{
struct library_path *p;
{
struct library_path *p;
- char path[
256
];
+ char path[
PATH_MAX
];
int fd = -1;
*dir = NULL;
int fd = -1;
*dir = NULL;
@@
-91,10
+96,10
@@
static int elf_open(char **dir, char *file)
return fd;
}
return fd;
}
-c
har* find_lib(
char *file)
+c
onst char* find_lib(const
char *file)
{
struct library *l;
{
struct library *l;
- static char path[
256
];
+ static char path[
PATH_MAX
];
const char *p;
l = avl_find_element(&libraries, file, l, avl);
const char *p;
l = avl_find_element(&libraries, file, l, avl);
@@
-110,7
+115,7
@@
char* find_lib(char *file)
return path;
}
return path;
}
-static int elf64_find_section(char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
+static int elf64_find_section(c
onst c
har *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
{
Elf64_Ehdr *e;
Elf64_Phdr *ph;
{
Elf64_Ehdr *e;
Elf64_Phdr *ph;
@@
-133,7
+138,7
@@
static int elf64_find_section(char *map, unsigned int type, unsigned int *offset
return -1;
}
return -1;
}
-static int elf32_find_section(char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
+static int elf32_find_section(c
onst c
har *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
{
Elf32_Ehdr *e;
Elf32_Phdr *ph;
{
Elf32_Ehdr *e;
Elf32_Phdr *ph;
@@
-156,7
+161,7
@@
static int elf32_find_section(char *map, unsigned int type, unsigned int *offset
return -1;
}
return -1;
}
-static int elf_find_section(char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
+static int elf_find_section(c
onst c
har *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
{
int clazz = map[EI_CLASS];
{
int clazz = map[EI_CLASS];
@@
-170,10
+175,10
@@
static int elf_find_section(char *map, unsigned int type, unsigned int *offset,
return -1;
}
return -1;
}
-static int elf32_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_offset)
+static int elf32_scan_dynamic(c
onst c
har *map, int dyn_offset, int dyn_size, int load_offset)
{
Elf32_Dyn *dynamic = (Elf32_Dyn *) (map + dyn_offset);
{
Elf32_Dyn *dynamic = (Elf32_Dyn *) (map + dyn_offset);
- char *strtab = NULL;
+ c
onst c
har *strtab = NULL;
while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) {
Elf32_Dyn *curr = dynamic;
while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) {
Elf32_Dyn *curr = dynamic;
@@
-204,10
+209,10
@@
static int elf32_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_
return 0;
}
return 0;
}
-static int elf64_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_offset)
+static int elf64_scan_dynamic(c
onst c
har *map, int dyn_offset, int dyn_size, int load_offset)
{
Elf64_Dyn *dynamic = (Elf64_Dyn *) (map + dyn_offset);
{
Elf64_Dyn *dynamic = (Elf64_Dyn *) (map + dyn_offset);
- char *strtab = NULL;
+ c
onst c
har *strtab = NULL;
while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) {
Elf64_Dyn *curr = dynamic;
while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) {
Elf64_Dyn *curr = dynamic;
@@
-238,7
+243,7
@@
static int elf64_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_
return 0;
}
return 0;
}
-int elf_load_deps(char *library)
+int elf_load_deps(c
onst c
har *library)
{
unsigned int dyn_offset, dyn_size;
unsigned int load_offset, load_vaddr;
{
unsigned int dyn_offset, dyn_size;
unsigned int load_offset, load_vaddr;
@@
-284,10
+289,12
@@
int elf_load_deps(char *library)
if (dir) {
alloc_library(dir, library);
} else {
if (dir) {
alloc_library(dir, library);
} else {
- char *elf = strdup(library);
+ char *elf1 = strdup(library);
+ char *elf2 = strdup(library);
- alloc_library(dirname(elf), basename(library));
- free(elf);
+ alloc_library(dirname(elf1), basename(elf2));
+ free(elf1);
+ free(elf2);
}
clazz = map[EI_CLASS];
}
clazz = map[EI_CLASS];
@@
-304,10
+311,10
@@
err_out:
return ret;
}
return ret;
}
-void load_ldso_conf(const char *conf)
+
static
void load_ldso_conf(const char *conf)
{
FILE* fp = fopen(conf, "r");
{
FILE* fp = fopen(conf, "r");
- char line[
256
];
+ char line[
PATH_MAX
];
if (!fp) {
DEBUG("failed to open %s\n", conf);
if (!fp) {
DEBUG("failed to open %s\n", conf);
@@
-317,7
+324,7
@@
void load_ldso_conf(const char *conf)
while (!feof(fp)) {
int len;
while (!feof(fp)) {
int len;
- if (!fgets(line,
256
, fp))
+ if (!fgets(line,
sizeof(line)
, fp))
break;
len = strlen(line);
if (len < 2)
break;
len = strlen(line);
if (len < 2)
@@
-343,13
+350,18
@@
void load_ldso_conf(const char *conf)
load_ldso_conf(gl.gl_pathv[i]);
globfree(&gl);
} else {
load_ldso_conf(gl.gl_pathv[i]);
globfree(&gl);
} else {
- struct stat s;
-
- if (stat(line, &s))
- continue;
alloc_library_path(line);
}
}
fclose(fp);
}
alloc_library_path(line);
}
}
fclose(fp);
}
+
+void init_library_search(void)
+{
+ avl_init(&libraries, avl_strcmp, false, NULL);
+ alloc_library_path("/lib");
+ alloc_library_path("/lib64");
+ alloc_library_path("/usr/lib");
+ load_ldso_conf("/etc/ld.so.conf");
+}