asanwrapper: remove all environment editing.
LD_LIBRARY_PATH that asanwrapper used to set is out-of-date.
The use case of "asanwrapper app_process" does not need LD_LIBRARY_PATH at all,
because asan/app_process is built with asan and the linker magic happens.
The use case of asanwrapper with a non-asan binary is not supported (and never was),
because it requires LD_PRELOAD.
ASAN_OPTIONS is unnecessary because the same setting can be found in /system/asan.options.
Also add a missing copyright header.
Bug: 36202343
Test: SANITIZE_LITE, setprop wrap.system_server=asanwrapper, observe that system_server loads libraries from /data/lib64.
Change-Id: Ic3ac252c2cf84efdeb6ca39dee4480ae68e01374
diff --git a/lib/asan/asanwrapper.cc b/lib/asan/asanwrapper.cc
index f4da969..6c6fd06 100644
--- a/lib/asan/asanwrapper.cc
+++ b/lib/asan/asanwrapper.cc
@@ -1,3 +1,31 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
#include <elf.h>
#include <fcntl.h>
#include <stdio.h>
@@ -17,37 +45,6 @@
exit(1);
}
-void env_prepend(const char* name, const char* value, const char* delim) {
- const char* value_old = getenv(name);
- std::string value_new = value;
- if (value_old) {
- value_new += delim;
- value_new += value_old;
- }
- setenv(name, value_new.c_str(), 1);
-}
-
-bool elf_is_64bit(const char* path) {
- int fd = open(path, O_RDONLY);
- if (fd == -1) return false;
-
- const size_t kBufSize = EI_CLASS + 1;
- char buf[kBufSize];
- ssize_t sz = read(fd, buf, kBufSize);
- if (sz != kBufSize) {
- close(fd);
- return false;
- }
-
- if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1 ||
- buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
- return false;
-
- bool is_64bit = buf[EI_CLASS] == ELFCLASS64;
- close(fd);
- return is_64bit;
-}
-
int main(int argc, char** argv) {
if (argc < 2) {
usage(argv[0]);
@@ -69,15 +66,6 @@
args[i] = argv[i + 1];
args[argc - 1] = 0;
- if (elf_is_64bit(args[0])) {
- env_prepend("LD_LIBRARY_PATH", "/system/lib64/asan:/system/lib64", ":");
- } else {
- env_prepend("LD_LIBRARY_PATH", "/system/lib/asan:/system/lib", ":");
- }
- env_prepend("ASAN_OPTIONS", "allow_user_segv_handler=1", ",");
-
- printf("ASAN_OPTIONS: %s\n", getenv("ASAN_OPTIONS"));
- printf("LD_LIBRARY_PATH: %s\n", getenv("LD_LIBRARY_PATH"));
for (int i = 0; i < argc - 1; ++i)
printf("argv[%d] = %s\n", i, args[i]);