diff options
-rw-r--r-- | configure.ac | 23 | ||||
-rw-r--r-- | src/Makefile.am | 14 | ||||
-rw-r--r-- | src/canonicalize.c | 3 | ||||
-rw-r--r-- | src/libsandbox.c | 9 | ||||
-rw-r--r-- | src/sandbox.c | 4 | ||||
-rw-r--r-- | src/sandbox.h | 5 | ||||
-rw-r--r-- | src/sandbox_utils.c (renamed from src/sandbox_futils.c) | 35 |
7 files changed, 82 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index 661bade..40cdabc 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,27 @@ else AC_DEFINE([TRUNCATE_T], [off_t], [truncate arg type]) fi +dnl Check if we have glibc or clone +AC_MSG_CHECKING([for glibc]) +AC_TRY_COMPILE([ +#include <features.h> +], [ +#if !defined(__GLIBC__) +# error no glibc +#endif + +int main (void) +{ + return 0; +} +], [have_glibc="yes"], [have_glibc="no"]) +if test x"$have_glibc" = xyes ; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi +AM_CONDITIONAL([HAVE_GLIBC], [test x"$have_glibc" = xyes]) + dnl we need to handle symbols differently based upon their version, dnl but we have to know which symbols the libc supports first AC_MSG_CHECKING([libc path]) @@ -109,7 +130,7 @@ AC_ARG_ENABLE([multilib], [enable_multilib="no"] ) -if test "$enable_multilib"x != xno ; then +if test x"$enable_multilib" != xno ; then AC_DEFINE_UNQUOTED([SB_HAVE_MULTILIB], [1], [have multilib enabled system]) fi diff --git a/src/Makefile.am b/src/Makefile.am index 32ac027..6b84b96 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,11 +4,15 @@ lib_LTLIBRARIES = libsandbox.la bin_PROGRAMS = sandbox AM_CPPFLAGS = \ - -D_GNU_SOURCE -DPIC -fPIC -D_REENTRANT \ - -DLIBSANDBOX_PATH=\"$(libdir)\" \ - -DSANDBOX_BASHRC_PATH=\"$(pkgdatadir)\" \ + -DPIC -fPIC -D_REENTRANT \ + -DLIBSANDBOX_PATH=\"$(libdir)\" \ + -DSANDBOX_BASHRC_PATH=\"$(pkgdatadir)\" \ -I$(top_srcdir) -Wall +if HAVE_GLIBC +AM_CPPFLAGS += -DHAVE_GLIBC +endif + LOCAL_INCLUDES = $(top_srcdir)/localdecls.h # We need -fexceptions here, else we do not catch exceptions @@ -24,14 +28,14 @@ libsandbox_la_SOURCES = \ libsandbox.c \ getcwd.c \ canonicalize.c \ - sandbox_futils.c \ + sandbox_utils.c \ $(LOCAL_INCLUDES) sandbox_CFLAGS = -DOUTSIDE_LIBSANDBOX sandbox_SOURCES = \ sandbox.c \ sandbox.h \ - sandbox_futils.c \ + sandbox_utils.c \ getcwd.c \ $(LOCAL_INCLUDES) diff --git a/src/canonicalize.c b/src/canonicalize.c index 97643b7..8a5c989 100644 --- a/src/canonicalize.c +++ b/src/canonicalize.c @@ -156,7 +156,8 @@ erealpath(const char *name, char *resolved) dest = rpath + dest_offset; } - dest = mempcpy(dest, start, end - start); + memcpy(dest, start, end - start); + dest += end - start; *dest = '\0'; } } diff --git a/src/libsandbox.c b/src/libsandbox.c index b8c44ec..af47a25 100644 --- a/src/libsandbox.c +++ b/src/libsandbox.c @@ -38,6 +38,9 @@ #define open xxx_open #define open64 xxx_open64 +#if defined(HAVE_GLIBC) +# define _GNU_SOURCE +#endif #include <dirent.h> #include <dlfcn.h> #include <errno.h> @@ -182,7 +185,7 @@ static void *get_dlsym(const char *symname, const char *symver) void *symaddr = NULL; if (NULL == libc_handle) { -#ifdef BROKEN_RTLD_NEXT +#if defined(BROKEN_RTLD_NEXT) || !defined(RTLD_NEXT) libc_handle = dlopen(LIBC_VERSION, RTLD_LAZY); if (!libc_handle) { fprintf(stderr, "libsandbox: Can't dlopen libc: %s\n", @@ -303,7 +306,7 @@ static char *resolve_path(const char *path, int follow_link) * file '/usr/lib/cf*' ...) */ snprintf(tmp_str2, SB_PATH_MAX, "%s", path); - bname = basename(tmp_str2); + bname = gbasename(tmp_str2); snprintf((char *)(filtered_path + strlen(filtered_path)), SB_PATH_MAX - strlen(filtered_path), "%s%s", (filtered_path[strlen(filtered_path) - 1] != '/') ? "/" : "", @@ -946,7 +949,7 @@ static void init_env_entries(char ***prefixes_array, int *prefixes_num, const ch pfx_array = malloc(((num_delimiters * 2) + 2) * sizeof(char *)); if (NULL == pfx_array) goto error; - buffer = strndup(prefixes_env, prefixes_env_length); + buffer = gstrndup(prefixes_env, prefixes_env_length); if (NULL == buffer) goto error; buffer_ptr = buffer; diff --git a/src/sandbox.c b/src/sandbox.c index 0356fd6..f4a985f 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -42,6 +42,8 @@ struct sandbox_info_t { static int print_debug = 0; static int stop_called = 0; +extern char **environ; + int sandbox_setup(struct sandbox_info_t *sandbox_info) { if (NULL != getenv(ENV_PORTAGE_TMPDIR)) { @@ -296,7 +298,7 @@ char **sandbox_setup_environ(struct sandbox_info_t *sandbox_info) } else { /* FIXME: Should probably free this at some stage - more neatness * than a real leak that will cause issues. */ - ld_preload_envvar = strndup(sandbox_info->sandbox_lib, + ld_preload_envvar = gstrndup(sandbox_info->sandbox_lib, strlen(sandbox_info->sandbox_lib)); if (NULL == ld_preload_envvar) return NULL; diff --git a/src/sandbox.h b/src/sandbox.h index dbfb6e8..0e33231 100644 --- a/src/sandbox.h +++ b/src/sandbox.h @@ -101,6 +101,11 @@ int is_dir(const char *pathname, int follow_link); long file_length(int fd); #endif /* OUTSIDE_LIBSANDBOX */ +/* Compat functions for GNU extensions */ +char *gstrndup (const char *str, size_t size); +/* Same as basename(3), but do not modify path */ +char *gbasename (const char *path); + /* glibc modified realpath() function */ char *erealpath(const char *, char *); char *egetcwd(char *, size_t); diff --git a/src/sandbox_futils.c b/src/sandbox_utils.c index 0d8ce27..c659842 100644 --- a/src/sandbox_futils.c +++ b/src/sandbox_utils.c @@ -2,6 +2,7 @@ * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> * Distributed under the terms of the GNU General Public License, v2 or later * Author: Brad House <brad@mainstreetsoftworks.com> + * Author: Martin Schlemmer <azarah@gentoo.org> * * $Header$ * @@ -165,5 +166,39 @@ long file_length(int fd) #endif /* OUTSIDE_LIBSANDBOX */ +char * gstrndup (const char *str, size_t size) +{ + char *new_str = NULL; + size_t len; + + if (NULL == str) + return NULL; + + /* Check lenght of str without breaching the size limit */ + for (len = 0; (len < size) && ('\0' != str[len]); len++); + + new_str = malloc (len + 1); + if (NULL == new_str) + return NULL; + + /* Make sure our string is NULL terminated */ + new_str[len] = '\0'; + + return (char *) memcpy (new_str, str, len); +} + +char * +gbasename (const char *path) +{ + char *new_path = NULL; + + if (NULL == path) + return NULL; + + /* Copied from glibc */ + new_path = strrchr (path, '/'); + return new_path ? new_path + 1 : (char *) path; +} + // vim:noexpandtab noai:cindent ai |