X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Falloc.c;h=c470b9d974c33a248edca731b19bce016f8396fe;hb=cb115640695b55ed9c0a8dbeb414219b09438aa7;hp=4089c00367444764cde7e8d2700d5f7bfff4ed49;hpb=79cdc4b6ea8848b21ba4a0e7d2fd3bc401e0bebe;p=debian%2Famanda diff --git a/common-src/alloc.c b/common-src/alloc.c index 4089c00..c470b9d 100644 --- a/common-src/alloc.c +++ b/common-src/alloc.c @@ -32,7 +32,6 @@ */ #include "amanda.h" #include "arglist.h" -#include "queue.h" #define MIN_ALLOC 64 @@ -104,7 +103,7 @@ debug_stralloc( * to scan the strings more than necessary. */ -#define MAX_VSTRALLOC_ARGS 32 +#define MAX_VSTRALLOC_ARGS 40 static char * internal_vstralloc( @@ -316,13 +315,11 @@ debug_vstrextend( return *oldstr; } - -extern char **environ; /* - * safe_env - build a "safe" environment list. + * safe_env_full - build a "safe" environment list. */ char ** -safe_env(void) +safe_env_full(char **add) { static char *safe_env_list[] = { "TZ", @@ -352,14 +349,24 @@ safe_env(void) size_t l1, l2; char **env; int env_cnt; + int nadd = 0; + + /* count ADD */ + for (p = add; p && *p; p++) + nadd++; if (getuid() == geteuid() && getgid() == getegid()) { env_cnt = 1; for (env = environ; *env != NULL; env++) env_cnt++; - if ((q = (char **)malloc(env_cnt*SIZEOF(char *))) != NULL) { + if ((q = (char **)malloc((nadd+env_cnt)*SIZEOF(char *))) != NULL) { envp = q; p = envp; + /* copy in ADD */ + for (env = add; env && *env; env++) { + *p = *env; + p++; + } for (env = environ; *env != NULL; env++) { if (strncmp("LANG=", *env, 5) != 0 && strncmp("LC_", *env, 3) != 0) { @@ -372,8 +379,15 @@ safe_env(void) return envp; } - if ((q = (char **)malloc(SIZEOF(safe_env_list))) != NULL) { + if ((q = (char **)malloc(nadd*sizeof(char *) + SIZEOF(safe_env_list))) != NULL) { envp = q; + /* copy in ADD */ + for (p = add; p && *p; p++) { + *q = *p; + q++; + } + + /* and copy any SAFE_ENV that are already set */ for (p = safe_env_list; *p != NULL; p++) { if ((v = getenv(*p)) == NULL) { continue; /* no variable to dup */ @@ -393,70 +407,3 @@ safe_env(void) } return envp; } - -/* - * amtable_alloc -- (re)allocate enough space for some number of elements. - * - * input: table -- pointer to pointer to table - * current -- pointer to current number of elements - * elsize -- size of a table element - * count -- desired number of elements - * bump -- round up factor - * init_func -- optional element initialization function - * output: table -- possibly adjusted to point to new table area - * current -- possibly adjusted to new number of elements - */ - -int -debug_amtable_alloc( - const char *file, - int line, - void ** table, - size_t * current, - size_t elsize, - size_t count, - int bump, - void (*init_func)(void *)) -{ - void *table_new; - size_t table_count_new; - size_t i; - - if (count >= *current) { - table_count_new = ((count + bump) / bump) * bump; - table_new = debug_alloc(file, line, table_count_new * elsize); - if (0 != *table) { - memcpy(table_new, *table, *current * elsize); - free(*table); - } - *table = table_new; - memset(((char *)*table) + *current * elsize, - 0, - (table_count_new - *current) * elsize); - if (init_func != NULL) { - for (i = *current; i < table_count_new; i++) { - (*init_func)(((char *)*table) + i * elsize); - } - } - *current = table_count_new; - } - return 0; -} - -/* - * amtable_free -- release a table. - * - * input: table -- pointer to pointer to table - * current -- pointer to current number of elements - * output: table -- possibly adjusted to point to new table area - * current -- possibly adjusted to new number of elements - */ - -void -amtable_free( - void ** table, - size_t * current) -{ - amfree(*table); - *current = 0; -}