From patchwork Wed Nov 25 17:54:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Champetier X-Patchwork-Id: 548682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4819C140291 for ; Thu, 26 Nov 2015 04:58:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Qmt6JGuT; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id E474728C045; Wed, 25 Nov 2015 18:56:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id C671C28A6D7 for ; Wed, 25 Nov 2015 18:55:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-wm0-f42.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 25 Nov 2015 18:55:03 +0100 (CET) Received: by wmec201 with SMTP id c201so267915442wme.0 for ; Wed, 25 Nov 2015 09:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xVGBU3ofFF23f5zQnrrA/Q0dLjzIW4Hul4U3mdm+wu8=; b=Qmt6JGuTKkc/WzgPnr6ci1WZa2RaHGHaaagfqZtkOBhSJ6Kml6Ug36SF9a8ImVYwHO tjo5s8QEAHuDbWQ3LQC/00N2HXufa2eK6NGWK94SiMBzPG+TU4V+PelYmLWnICaYxZoc weqDY2an2BdMY3qd46tY/UkiSN7EqXBSBcqBNbQK5wprMMN7YEU71NALViadtEcthVKo 80pfdnxT7yRj5zdSrLl4Bw9oxz6xgF0OyRYcidwJG+/8XFA8dSCGVncGNCkcWHkmjs4C 9E7ICpNtX/h/+8dXmkVcA2YFrhT7PN/3pqOI7i4Ffw1S30i/vZlswW3Z3FbJ2ZlpjgGb o7iQ== X-Received: by 10.194.21.170 with SMTP id w10mr51725723wje.29.1448474102953; Wed, 25 Nov 2015 09:55:02 -0800 (PST) Received: from ubuntu1404.lxcnattst (ns623510.ovh.net. [5.135.134.9]) by smtp.gmail.com with ESMTPSA id cv3sm24180221wjc.20.2015.11.25.09.55.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Nov 2015 09:55:02 -0800 (PST) From: Etienne CHAMPETIER To: OpenWrt Development List Date: Wed, 25 Nov 2015 17:54:37 +0000 Message-Id: <1448474090-30280-5-git-send-email-champetier.etienne@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448474090-30280-1-git-send-email-champetier.etienne@gmail.com> References: <1448474090-30280-1-git-send-email-champetier.etienne@gmail.com> Subject: [OpenWrt-Devel] [PATCH procd v2 04/17] ujail: use more const in elf.* X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Etienne CHAMPETIER --- jail/elf.c | 28 +++++++++++++++------------- jail/elf.h | 4 ++-- jail/jail.c | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/jail/elf.c b/jail/elf.c index 34a5aca..fb046b4 100644 --- a/jail/elf.c +++ b/jail/elf.c @@ -69,7 +69,7 @@ static void alloc_library(const char *path, const char *name) DEBUG("adding library %s/%s\n", path, name); } -static int elf_open(char **dir, char *file) +static int elf_open(char **dir, const char *file) { struct library_path *p; char path[256]; @@ -95,7 +95,7 @@ static int elf_open(char **dir, char *file) return fd; } -char* find_lib(char *file) +const char* find_lib(const char *file) { struct library *l; static char path[256]; @@ -114,7 +114,7 @@ char* find_lib(char *file) 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(const char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr) { Elf64_Ehdr *e; Elf64_Phdr *ph; @@ -137,7 +137,7 @@ static int elf64_find_section(char *map, unsigned int type, unsigned int *offset 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(const char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr) { Elf32_Ehdr *e; Elf32_Phdr *ph; @@ -160,7 +160,7 @@ static int elf32_find_section(char *map, unsigned int type, unsigned int *offset 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(const char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr) { int clazz = map[EI_CLASS]; @@ -174,10 +174,10 @@ static int elf_find_section(char *map, unsigned int type, unsigned int *offset, return -1; } -static int elf32_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_offset) +static int elf32_scan_dynamic(const char *map, int dyn_offset, int dyn_size, int load_offset) { Elf32_Dyn *dynamic = (Elf32_Dyn *) (map + dyn_offset); - char *strtab = NULL; + const char *strtab = NULL; while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) { Elf32_Dyn *curr = dynamic; @@ -208,10 +208,10 @@ static int elf32_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_ return 0; } -static int elf64_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_offset) +static int elf64_scan_dynamic(const char *map, int dyn_offset, int dyn_size, int load_offset) { Elf64_Dyn *dynamic = (Elf64_Dyn *) (map + dyn_offset); - char *strtab = NULL; + const char *strtab = NULL; while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) { Elf64_Dyn *curr = dynamic; @@ -242,7 +242,7 @@ static int elf64_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_ return 0; } -int elf_load_deps(char *library) +int elf_load_deps(const char *library) { unsigned int dyn_offset, dyn_size; unsigned int load_offset, load_vaddr; @@ -288,10 +288,12 @@ int elf_load_deps(char *library) 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]; diff --git a/jail/elf.h b/jail/elf.h index 19ceb3e..ddbe234 100644 --- a/jail/elf.h +++ b/jail/elf.h @@ -31,8 +31,8 @@ struct library_path { extern struct avl_tree libraries; void alloc_library_path(const char *path); -char* find_lib(char *file); -int elf_load_deps(char *library); +int elf_load_deps(const char *library); +const char* find_lib(const char *file); void load_ldso_conf(const char *conf); #endif diff --git a/jail/jail.c b/jail/jail.c index 9952ed9..52f88ef 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -212,7 +212,7 @@ static char** build_envp(const char *seccomp) static char preload_var[64]; static char seccomp_var[64]; static char debug_var[] = "LD_DEBUG=all"; - char *preload_lib = find_lib("libpreload-seccomp.so"); + const char *preload_lib = find_lib("libpreload-seccomp.so"); int count = 0; if (seccomp && !preload_lib) {