#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "sandbox/linux/services/libc_interceptor.h"
#include <dlfcn.h>
#include <fcntl.h>
#include <netdb.h>
#include <pthread.h>
#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <set>
#include <string>
#include "base/compiler_specific.h"
#include "base/debug/dump_without_crashing.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/pickle.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/global_descriptors.h"
#include "base/posix/unix_domain_socket.h"
#include "base/sanitizer_buildflags.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
#if BUILDFLAG(USING_SANITIZER) && !defined(COMPONENT_BUILD)
#define INTERCEPTOR_DECL …
#define REAL …
#else
#define INTERCEPTOR_DECL(...) …
#define REAL(func) …
#endif
#define DLSYM_FUNC_DECL(ret_type, func, ...) …
#define DLSYM_FUNC_BODY(func, dlsym_failed_return_val, ...) …
#define CALL_FUNC(func, ...) …
DLSYM_FUNC_DECL(int,
getaddrinfo,
const char* node,
const char* service,
const struct addrinfo* hints,
struct addrinfo** res) { … }
namespace sandbox {
namespace {
bool g_am_zygote_or_renderer = …;
int g_backchannel_fd = …;
base::LazyInstance<std::set<std::string>>::Leaky g_timezones = …;
base::LazyInstance<base::Lock>::Leaky g_timezones_lock = …;
bool ReadTimeStruct(base::PickleIterator* iter,
struct tm* output,
char* timezone_out,
size_t timezone_out_len) { … }
void WriteTimeStruct(base::Pickle* pickle, const struct tm& time) { … }
void ProxyLocaltimeCallToBrowser(time_t input,
struct tm* output,
char* timezone_out,
size_t timezone_out_len) { … }
bool HandleLocalTime(int fd,
base::PickleIterator iter,
const std::vector<base::ScopedFD>& fds) { … }
}
LocaltimeFunction;
LocaltimeRFunction;
static pthread_once_t g_libc_localtime_funcs_guard = …;
static LocaltimeFunction g_libc_localtime;
static LocaltimeFunction g_libc_localtime64;
static LocaltimeRFunction g_libc_localtime_r;
static LocaltimeRFunction g_libc_localtime64_r;
static void InitLibcLocaltimeFunctionsImpl() { … }
__attribute__((__visibility__("default"))) struct tm* localtime_override(
const time_t* timep) __asm__("localtime");
NO_SANITIZE("cfi-icall")
__attribute__((__visibility__("default"))) struct tm* localtime_override(
const time_t* timep) { … }
__attribute__((__visibility__("default"))) struct tm* localtime64_override(
const time_t* timep) __asm__("localtime64");
NO_SANITIZE("cfi-icall")
__attribute__((__visibility__("default"))) struct tm* localtime64_override(
const time_t* timep) { … }
__attribute__((__visibility__("default"))) struct tm* localtime_r_override(
const time_t* timep,
struct tm* result) __asm__("localtime_r");
NO_SANITIZE("cfi-icall")
__attribute__((__visibility__("default"))) struct tm* localtime_r_override(
const time_t* timep,
struct tm* result) { … }
__attribute__((__visibility__("default"))) struct tm* localtime64_r_override(
const time_t* timep,
struct tm* result) __asm__("localtime64_r");
NO_SANITIZE("cfi-icall")
__attribute__((__visibility__("default"))) struct tm* localtime64_r_override(
const time_t* timep,
struct tm* result) { … }
void SetAmZygoteOrRenderer(bool enable, int backchannel_fd) { … }
bool HandleInterceptedCall(int kind,
int fd,
base::PickleIterator iter,
const std::vector<base::ScopedFD>& fds) { … }
void InitLibcLocaltimeFunctions() { … }
namespace {
std::atomic<bool> g_getaddrinfo_discouraged{ … };
}
extern "C" {
__attribute__((visibility("default"), noinline)) int getaddrinfo(
const char* node,
const char* service,
const struct addrinfo* hints,
struct addrinfo** res) { … }
}
void DiscourageGetaddrinfo() { … }
}