This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Hi Uli, please test the appended patch. Now ldconfig doesn't call chroot anymore. Ok to commit? Andreas 2000-09-26 Andreas Jaeger <aj@suse.de> * elf/ldconfig.c (parse_opt): Remove trailing slashes from opt_chroot. (search_dir): Handle chroot. (setup_file): New function. (main): Use it to handle chroot. ============================================================ Index: elf/ldconfig.c --- elf/ldconfig.c 2000/09/24 18:35:02 1.7 +++ elf/ldconfig.c 2000/09/26 14:03:40 @@ -105,14 +105,16 @@ /* Path to root for chroot. */ static char *opt_chroot; +static int use_chroot; + /* Manually link given shared libraries. */ static int opt_manual_link = 0; /* Cache file to use. */ -static const char *cache_file; +static char *cache_file; /* Configuration file. */ -static const char *config_file; +static char *config_file; /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); @@ -221,7 +223,19 @@ opt_print_cache = 1; break; case 'r': - opt_chroot = arg; + { + size_t len = strlen (arg); + opt_chroot = arg; + use_chroot = 1; + + /* Make sure that opt_chroot ends without a slash. */ + len = strlen (opt_chroot); + while (len && opt_chroot [len - 1] == '/') + { + --len; + opt_chroot [len] = '\0'; + } + } break; case 'v': opt_verbose = 1; @@ -512,7 +526,7 @@ DIR *dir; struct dirent *direntry; char buf [PATH_MAX]; - char *soname; + char *soname, *buf_ptr; struct dlib_entry *dlibs; struct dlib_entry *dlib_ptr; int nchars; @@ -529,8 +543,26 @@ else printf ("%s:\n", entry->path); } + + if (use_chroot) + buf_ptr = stpncpy (buf, opt_chroot, sizeof (buf)); + else + buf_ptr = buf; + + buf_ptr = stpncpy (buf_ptr, entry->path, sizeof (buf) - (buf_ptr - buf)); + /* Check for overflow. */ + if ((buf_ptr - buf) >= sizeof (buf)) + { + if (use_chroot) + error (0, 0, _("Length of directory %s%s is too large -- directory is ignored\n"), + opt_chroot, entry->path); + else + error (0, 0, _("Length of directory %s is too large -- directory is ignored\n"), + entry->path); + return; + } - dir = opendir (entry->path); + dir = opendir (buf); if (dir == NULL) { if (opt_verbose) @@ -558,13 +590,21 @@ || strstr (direntry->d_name, ".so") == NULL) && !is_hwcap (direntry->d_name)) continue; - nchars = snprintf (buf, sizeof (buf), "%s/%s", entry->path, - direntry->d_name); + if (use_chroot) + nchars = snprintf (buf, sizeof (buf), "%s%s/%s", opt_chroot, entry->path, + direntry->d_name); + else + nchars = snprintf (buf, sizeof (buf), "%s/%s", entry->path, + direntry->d_name); /* Check for overflow. */ if (nchars >= (int) sizeof (buf)) { - error (0, 0, _("buffer for snprintf too small for %s/%s--file is ignored\n"), - entry->path, direntry->d_name); + if (use_chroot) + error (0, 0, _("Length of file %s%s/%s is too large -- file is ignored\n"), + opt_chroot, entry->path, direntry->d_name); + else + error (0, 0, _("Length of file %s/%s is too large -- file is ignored\n"), + entry->path, direntry->d_name); continue; } #ifdef _DIRENT_HAVE_D_TYPE @@ -582,10 +622,14 @@ { /* Handle subdirectory later. */ struct dir_entry *new_entry; + char tmp [PATH_MAX]; new_entry = xmalloc (sizeof (struct dir_entry)); + /* No need to check for overflow. */ + nchars = snprintf (tmp, sizeof (tmp), "%s/%s", entry->path, + direntry->d_name); - new_entry->path = buf; + new_entry->path = xstrdup (tmp); new_entry->flag = entry->flag; new_entry->next = NULL; add_single_dir (new_entry, 0); @@ -761,7 +805,34 @@ fclose (file); } +static char * +setup_file (const char *file, const char *default_name) +{ + char *res, *tmp; + int len_chroot = use_chroot ? strlen (opt_chroot) : 0; + if (file == NULL) + { + res = xmalloc (len_chroot + strlen (default_name) + 1); + tmp = res; + if (use_chroot) + tmp = stpcpy (tmp, opt_chroot); + stpcpy (tmp, default_name); + } + else + { + res = xmalloc (len_chroot + strlen (file) + 1); + + tmp = res; + if (use_chroot) + tmp = stpcpy (tmp, opt_chroot); + stpcpy (tmp, file); + } + + return res; +} + + int main (int argc, char **argv) { @@ -779,27 +850,13 @@ add_dir (argv [i]); } - if (cache_file == NULL) - cache_file = LD_SO_CACHE; + cache_file = setup_file (cache_file, LD_SO_CACHE); + config_file = setup_file (config_file, LD_SO_CONF); - if (config_file == NULL) - config_file = LD_SO_CONF; - - /* Chroot first. */ - if (opt_chroot) - { - if (chroot (opt_chroot)) - /* Report failure and exit program. */ - error (EXIT_FAILURE, errno, _("Can't chroot to %s"), opt_chroot); - /* chroot doesn't change the working directory, let's play safe. */ - if (chdir ("/")) - error (EXIT_FAILURE, errno, _("Can't chdir to /")); - } - if (opt_print_cache) { print_cache (cache_file); - exit (0); + goto cleanup; } if (opt_manual_link) @@ -810,10 +867,9 @@ for (i = remaining; i < argc; ++i) manual_link (argv [i]); - exit (0); + goto cleanup; } - if (opt_build_cache) init_cache (); @@ -831,6 +887,12 @@ if (opt_build_cache) save_cache (cache_file); + + /* Cleanup. */ + cleanup: + + free (cache_file); + free (config_file); return 0; } -- Andreas Jaeger SuSE Labs aj@suse.de private aj@arthur.inka.de http://www.suse.de/~aj
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |