X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Falloc.c;h=50cfc084772911587884597618930ffab6302a57;hb=d3b2175e084f88c8736ad7073eacbf4670147aec;hp=81670ea80bcbab0a131adccc0635db99553c6e71;hpb=34197d9f46a5f4e944378cbb65fca32ee0eec7b9;p=debian%2Famanda diff --git a/common-src/alloc.c b/common-src/alloc.c index 81670ea..50cfc08 100644 --- a/common-src/alloc.c +++ b/common-src/alloc.c @@ -34,6 +34,7 @@ #include "arglist.h" #include "queue.h" +#define MIN_ALLOC 64 static char *internal_vstralloc(const char *, va_list); /* @@ -383,6 +384,43 @@ arglist_function1( } +/* + * vstrallocf - copies printf formatted string into newly allocated memory. + */ +char * +debug_vstrallocf( + const char *fmt, + ...) +{ + char * result; + size_t size; + va_list argp; + + debug_alloc_pop(); + malloc_enter(debug_caller_loc(saved_file, saved_line)); + + result = debug_alloc(saved_file, saved_line, MIN_ALLOC); + if (result != NULL) { + + arglist_start(argp, fmt); + size = vsnprintf(result, MIN_ALLOC, fmt, argp); + arglist_end(argp); + + if (size >= (size_t)MIN_ALLOC) { + amfree(result); + result = debug_alloc(saved_file, saved_line, size + 1); + + arglist_start(argp, fmt); + (void)vsnprintf(result, size + 1, fmt, argp); + arglist_end(argp); + } + } + + malloc_leave(debug_caller_loc(saved_file, saved_line)); + return result; +} + +extern char **environ; /* * safe_env - build a "safe" environment list. */ @@ -415,6 +453,27 @@ safe_env(void) char *s; char *v; size_t l1, l2; + char **env; + int env_cnt; + + 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) { + envp = q; + p = envp; + for (env = environ; *env != NULL; env++) { + if (strncmp("LANG=", *env, 5) != 0 && + strncmp("LC_", *env, 3) != 0) { + *p = stralloc(*env); + p++; + } + } + *p = NULL; + } + return envp; + } if ((q = (char **)malloc(SIZEOF(safe_env_list))) != NULL) { envp = q;